Creating Offline Gadgets for Task Business Data
You can create gadgets that support the offline mode in Mobile Business Console. These offline gadgets are used in Mobile Business Console for displaying task business data.
To create an offline task gadget
1. Enable the gadget to cache data offline as follows:
a. Navigate to gadgetDefinition.xml of the gadget.
b. Select the Gadget Definition Editor tab and expand Parameters.
c. Click Add.
d. Specify the following parameter in the Name and Value fields respectively:
2. Configure the caching as follows:
a. Navigate to the gadget controller.
b. Define the REST service URL with the caching configuration as follows:
Ensure that the URL is accessible from $scope.
URLS : {
TASK_DETAILS_GET : {
url : '/rest/pub/opentask',
method : 'GET',
serverType : SERVER_TYPES.TE,
caching :
{
name : 'MBC_OFFLINE_TASK_DATA',
key : {requestKeyParamName : 'taskID'},
strategy : 'CacheFirst',
autoSynch : {
synchurl : '/rest/pub/opentask',
method : 'PUT',
queryParams : [{name : 'taskID',
valueKeyPath : 'taskInfo.taskID'}]
}
}
},
TASK_DETAILS_POST : {
url : '/rest/pub/opentask',
method : 'PUT',
serverType : SERVER_TYPES.TE,
caching : {
name : 'MBC_OFFLINE_TASK_DATA',
key : {
requestKeyParamName : 'taskID',
updateReadKeyPath : 'taskData',
updateWriteKeyPath : 'taskData'
}
}
}
}
3. Set the scope and parameter values.
In case of REST service execution by passing parameters to the invoke() function:
var parameter = [{"name" :"includeTaskData","value":"true"},
{"name": "taskID" ,"value" : _$scope.config.params.taskID}];
_$scope.restClient.invoke(_$scope.URLS.TASK_DETAILS_GET,
function(response){
console.log("Success");
},
function(response, status, header, config, _$scope){
console.log("Error");
},
parameter,
null,
_$scope,
null,null);
In case of UI generated using Integration Server REST drag and drop:
var parameter = [{"name" :"includeTaskData","value":"true"},
{"name": "taskID" ,"value" : _$scope.config.params.taskID}];
_$scope.restClient.url(<IS REST EndPoint with parameter>)
.remote(true)
.scope(_$scope)
.serverAlias("HostEntry1")
.gadgetConfig(_$scope.config)
.method("GET")
.header("Accept","application/json")
.caching(_$scope.URLS.TASK_DETAILS_GET.caching)
.parameter(parameter)
.success()
.error()
.invoke();
REST wrapper input and output must exactly match the corresponding Task Engine REST API rest/pub/opentask. For more information, see webMethods Task Engine API and Service Reference.
4. Fetch the details again to synch the task instance version number with the cache after a business data update.
//Task data updates success call back
function(response,status) {
/*
Custom logic
*/
if ((status && status != "CACHE")){
//Re-fetch the task data
}
}
5. Verify if the response received is of type String and then convert it to JSON format.
//Task data gets success call back
function(response,status) {
if (response.taskData){
if (jQuery.type(response.taskData) === 'string') {
_$scope.restData = JSON.parse(response.taskData);
} else {
_$scope.restData = response.taskData;
}
}
/*
Custom logic
*/
}
6. Configure the task type to use the offline gadget to display the business data in Designer.