How To: Use Mode Conditions
The Mode conditions allow you to build rules around views and forms for when they are defined as Offline. K2 Mobile makes use of the behavior associated with the mode parameter set to Offline, and so can be used as the front-end for forms. All other platforms will execute within Normal mode.
You can use the following permutations with the Mode conditions:
Permutation | Description |
---|---|
Offline | Forms and Views have limited functionality and work without a connection to the server. |
Normal | Forms and Views have full functionality and require a connection to the server. |
One example is where the device is offline when opening the form in K2 Mobile, you can send a message to inform the user of the offline status.
You can also create an advanced condition to check the mode status before executing an action by dragging Mode from the System Values of the Context Browser.
How to use a Mode condition
- Create a SmartObject.
- Create an Item view of the SmartObject containing a Create button.
- Edit the When Create Button is Clicked rule and add the following conditions and actions:
- Configure the message as follows and drag Mode from the Context Browser into the mail as shown below:
- Save the rule and the view.
- Add the view to a form.
- Select the Offline Availability setting in the Advanced section of the form properties. This enables the offline mode condition to execute when the form is offline.
- Select the Application Form setting in the Advanced section of the form properties. This makes the form available in the Forms folder of the K2 Mobile app.
- Save the form.
- Check in the view and form.
- Move the form to the System > Application Forms folder so that it is available as an application form in the K2 Mobile app.
- Open the form from the K2 Mobile app.
- Change the settings in K2 Mobile to be offline.
- Capture some data and click the Create button.
- The message displays.
- To test the rules before using it on the device, run the view and insert ?_mode=offline into the query string (url) of the page as shown below:
Considerations
- The mode is determined by the mobile device's status when the form is opened. For example if the mobile device is offline, the mode reflects as offline and views and forms are in turn offline. If the mobile device's status change to offline while a user is capturing data for example, the information is saved in the Outbox and submitted when the mobile is online again.
- The mode should not be confused with the Offline Availability setting of the form properties. The Offline Availability setting in the form properties needs to be set to enable the offline mode conditions to work for K2 Mobile.
- If a form contains a view and the form is offline, the view inherits the offline setting. The same principle is applicable to subviews and subforms.
- When creating rules around the offline mode feature, it is important to note that only client side actions execute when the mobile device is offline. Server side actions will NOT be available while the mobile device is offline.
- It may be a good idea to perform offline mode conditions and actions in a batch when the view/form initializes to inform the user at that point already if the device is offline.