We start by creating a Business Object and inserting the annotations. [OfflineEnabled][WithAdministrativeData(IncludeSubnodes)]
Before the new BO can be saved we need to define at least one element on the root node.
Save & Activate the newly created Business Object
The next step is to create the screens. The following pop-up will show:
You will notice that the Thing-based Navigation screens are being generated and the option for Object Based Navigation screens is not possible (This is because only Thing-based navigation is supported for offline).
Let's create a Before-Save event script on the Root Node and a Validation event on the Item Node
Let us populate the Validation event with some code:
In this case if the price is less than 5 the validation should not go through i.e the Item should not be persisted into the database.
Now let's do the same for the Before-Save event, here we are setting a Fixed price on the item from the Root level.
Now we will activate both of the scripts (BeforeSave and Validation) and proceed to test the functionality from the UI.
To open the test offline environment you will have to modify the URL adding the following:
https://myXXXXXX.crm.ondemand.com/sap/public/ap/ui/repository/SAP_BYD_UI/HTML5/newofflinewin.html
You will be asked to create a passcode. This is done so that users on mobile devices can access the environment quicker.
When we expand the user drop-down, the "Go Offline" button will be greyed out. Before going Offline a Synchronisation has to be performed to download the content that will be used while the user is in the offline mode.
You can view the content that will be downloaded by going to the "Offline Settings". More detailed configurations can be accessed by navigating to the Administrator WorkCenter > General Settings View and opening the Offline Settings screen (this will be covered in a separate blog in more details).
The OWL can now be accessed. However, since there are no instances available, let's perform a sync and go offline where we will add an instance.
To perform the sync you can either click "Sync Now" in the user drop-down or simply click the Sync button in the top right corner.
The progress of the sync can be monitored by clicking the Sync button once again.
As per the warning message when performing a sync on a mobile device do not close the application as this will impact the sync.
Once the sync is finished we can now "Go Offline"
Once in Offline mode you will notice significantly less WorkCenters available, and the "Go Offline" button is now called "Go Online".
Let's create an instance in the Custom Business Object.
You can notice a little orange identifier beside the UUID, this means that the particular instance was created while being Offline and is not Synchronized.
The Sync Button also has a notification available informing the user that there are synchronized changes (Note: Automatic synchronization occurs depending on the configuration).
Having performed the Sync, let's return back to the Online environment by pressing the "Go Online" button in the user drop-down.
We can see that the instance is now available and the orange identifier is gone meaning the instance is persisted into the database.
There is also a log available which features all the changes that were made during a sync. You can view by navigating to the Offline Settings (from the user drop-down) and inspecting the "Upload Sync Log".
3 different filters are available, which can aid in troubleshooting should a sync of an instance fail:
Click the magnifying glass to directly navigate to the processed instance.
Debugging:
You can access the generated scripts from the Developer Console in the browser, to find the particular script search for the solution Y name.
Note: The scripts will only be available when the particular Business Object instance is opened/is being created.
You can see the JavaScript representation of our Before Save script above. We can debug the same by setting a breakpoint directly in the generated script.
Let us test if the validation message is raised for the Item node correctly in the Offline environment.
Note: It is important to understand that during a Sync the Online Scripts will be called, hence if the coding is not reflected in both Online & Offline scripts the data can vary between the Online and Offline environments.
Thanks for reading, more information to come with the next blog series!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
10 | |
10 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |