{"id":15132,"date":"2019-03-20T11:39:22","date_gmt":"2019-03-20T11:39:22","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=15132"},"modified":"2019-06-28T05:54:08","modified_gmt":"2019-06-28T05:54:08","slug":"working-with-fetch-functions-of-jsbridge-reference-file-in-online-and-offline-mode-of-resco-mobile-app","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2019\/03\/working-with-fetch-functions-of-jsbridge-reference-file-in-online-and-offline-mode-of-resco-mobile-app\/","title":{"rendered":"Working with Fetch functions of JSBridge Reference file in Online and Offline Mode of Resco Mobile App"},"content":{"rendered":"<p><strong>Introduction:<\/strong><\/p>\n<p>Recently, we had a business requirement where we needed to display total number of active <strong>Agreement <\/strong>records associated to the <strong>Account<\/strong> entity of<strong> Dynamics 365 CRM <\/strong>on \u201cAccount Entity Form\u201d in Resco mobile app.<\/p>\n<p>So, we developed a script for populating total number of active <strong>Agreements <\/strong>related to the <strong>Account record<\/strong> and deployed it on the entity form of <strong>Account <\/strong>entity in Resco Mobile App.<\/p>\n<p>Following is the function that we were using in Javascript,<\/p>\n<p>Code Snippet:<\/p>\n<p>\/\/Executing fetch<\/p>\n<p>fetch.execute(&#8220;DynamicEntities&#8221;, function (result) {<\/p>\n<p>if (typeof (result) != &#8220;undefined&#8221; &amp;&amp; result.length &gt; 0) {<\/p>\n<p>\/\/Setting &#8220;new_totalagreements&#8221; feild<\/p>\n<p>entityForm.entity.properties[&#8220;new_totalagreements&#8221;] = result.length.toString();<\/p>\n<p>}<\/p>\n<p>}, function (error) {<\/p>\n<p>MobileCRM.bridge.alert(&#8220;An Error Has occurred &#8221; + error)<\/p>\n<p>});<\/p>\n<p>After deploying the script on Resco Mobile App, when the user opened an Account record on \u201cOffline\u201d mode it worked as expected, but when the user opened an Account record on \u201cOnline\u201d mode it did not work and an Exception was thrown.<\/p>\n<p>Please refer below screenshot,<\/p>\n<p><strong>Online Mode: <\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-19325\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/1JSBridge.png\" alt=\"JSBridge\" width=\"1366\" height=\"730\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/1JSBridge.png 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/1JSBridge-300x160.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/1JSBridge-768x410.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/1JSBridge-1024x547.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/1JSBridge-660x353.png 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>So we have used \u201cfetch.executeOffline()\u201d function instead of \u201cfetch.execute()\u201d which has fixed this issue. And the \u201cfetch.executeOffline()\u201d works on both \u201cOnline and Offline Mode\u201d for executing the fetch.<\/p>\n<p>Code Snippet:<\/p>\n<p>\/\/Executing fetch<\/p>\n<p>fetch.<strong>executeOffline<\/strong>(&#8220;DynamicEntities&#8221;, function (result) {<\/p>\n<p>if (typeof (result) != &#8220;undefined&#8221; &amp;&amp; result.length &gt; 0) {<\/p>\n<p>\/\/Setting &#8220;new_totalagreements&#8221; feild<\/p>\n<p>entityForm.entity.properties[&#8220;new_totalagreements&#8221;] = result.length.toString();<\/p>\n<p>}<\/p>\n<p>}, function (error) {<\/p>\n<p>MobileCRM.bridge.alert(&#8220;An Error Has occurred &#8221; + error)<\/p>\n<p>});<\/p>\n<p>Please refer below screenshots,<\/p>\n<p><strong>Online Mode: <img decoding=\"async\" class=\"aligncenter size-full wp-image-15134\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/resco-1.png\" alt=\"\" width=\"1366\" height=\"729\" \/><\/strong><\/p>\n<p><strong>Offline Mode:<\/strong><\/p>\n<p><strong><img decoding=\"async\" class=\"aligncenter size-full wp-image-15135\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/03\/resco-2.png\" alt=\"\" width=\"1366\" height=\"727\" \/><\/strong><\/p>\n<p><strong>\u00a0<\/strong><strong>Conclusion:<\/strong><\/p>\n<p>While executing fetch function in Java script in Resco Mobile App through JSBridge Reference file, we should use \u00a0\u201cfetch.executeOffline()\u201d instead of \u201cfetch.execute()\u201d to fetch data in both the Online Mode and Offline Mode of Resco mobile app.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 \u201cAccount Entity Form\u201d in Resco mobile app. So, we developed a script for populating total number of active Agreements related to the Account record and deployed it\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2019\/03\/working-with-fetch-functions-of-jsbridge-reference-file-in-online-and-offline-mode-of-resco-mobile-app\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":15140,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[48,1],"tags":[533,1444],"class_list":["post-15132","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-resco-mobile-crm","category-uncategorized","tag-dynamics-365","tag-resco-mobile"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/15132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=15132"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/15132\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/15140"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=15132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=15132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=15132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}