Working with Fetch functions of JSBridge Reference file in Online and Offline Mode of Resco Mobile App

By | March 20, 2019

Introduction:

Recently, we had a business requirement where we needed to display total number of active Agreement records associated to the Account entity of Dynamics 365 CRM on “Account Entity Form” in Resco mobile app.

So, we developed a script for populating total number of active Agreements related to the Account record and deployed it on the entity form of Account entity in Resco Mobile App.

Following is the function that we were using in Javascript,

Code Snippet:

//Executing fetch

fetch.execute(“DynamicEntities”, function (result) {

if (typeof (result) != “undefined” && result.length > 0) {

//Setting “new_totalagreements” feild

entityForm.entity.properties[“new_totalagreements”] = result.length.toString();

}

}, function (error) {

MobileCRM.bridge.alert(“An Error Has occurred ” + error)

});

After deploying the script on Resco Mobile App, when the user opened an Account record on “Offline” mode it worked as expected, but when the user opened an Account record on “Online” mode it did not work and an Exception was thrown.

Please refer below screenshot,

Online Mode:

JSBridge

So we have used “fetch.executeOffline()” function instead of “fetch.execute()” which has fixed this issue. And the “fetch.executeOffline()” works on both “Online and Offline Mode” for executing the fetch.

Code Snippet:

//Executing fetch

fetch.executeOffline(“DynamicEntities”, function (result) {

if (typeof (result) != “undefined” && result.length > 0) {

//Setting “new_totalagreements” feild

entityForm.entity.properties[“new_totalagreements”] = result.length.toString();

}

}, function (error) {

MobileCRM.bridge.alert(“An Error Has occurred ” + error)

});

Please refer below screenshots,

Online Mode:

Offline Mode:

 Conclusion:

While executing fetch function in Java script in Resco Mobile App through JSBridge Reference file, we should use  “fetch.executeOffline()” instead of “fetch.execute()” to fetch data in both the Online Mode and Offline Mode of Resco mobile app.