{"id":24130,"date":"2020-07-16T11:52:57","date_gmt":"2020-07-16T11:52:57","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=24130"},"modified":"2020-07-16T11:52:57","modified_gmt":"2020-07-16T11:52:57","slug":"how-to-add-loader-on-screen-in-resco-mobile-app","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/07\/how-to-add-loader-on-screen-in-resco-mobile-app\/","title":{"rendered":"How to add loader on screen in Resco Mobile App"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>While working with the script (using <strong>JSbridge<\/strong> reference) in <strong>Resco Mobile App<\/strong>, sometimes it takes more time to perform the operation since the process is async in the Resco Mobile app. If we want to hold the screen till the completion of process, we need to add loader or processing bar on the page which gives an idea to the user\/technician that the operation is in progress and user\/technician needs to wait on the page.<\/p>\n<p>Because if the user\/technician navigates to another page before completion of the script in the background then it might break the functionality in between.<\/p>\n<p>In <strong>Resco<\/strong> there is <strong>showPleaseWait<\/strong> function which will freeze the screen until the process is completed.<\/p>\n<p>For example, in update of \u2018Main Phone\u2019 on <strong>Account<\/strong> form we want to update related Contact\u2019s \u2018Business Phone\u2019 same as \u2018Main Phone\u2019. There can be several <strong>Contacts<\/strong> related to the <strong>Account<\/strong> and since the process is async, it takes time to update the \u2018Business Phone\u2019 of related <strong>Contacts<\/strong>. So, using<strong> showPleaseWait<\/strong> JSBridge function, we can add loader until the process execution completes.<\/p>\n<p>Please refer below code for the same:<\/p>\n<p>function onLoad() {<\/p>\n<p>var functionName = &#8220;onLoad(): &#8220;;<\/p>\n<p>try {<\/p>\n<p>MobileCRM.UI.EntityForm.onChange(function (entityForm) {<\/p>\n<p>var changedItem = entityForm.context.changedItem;<\/p>\n<p>\/\/validate the changed item<\/p>\n<p>if (changedItem == &#8220;telephone1&#8221;) {<\/p>\n<p>var accountId = entityForm.entity.id;<\/p>\n<p>var telephone1 = entityForm.entity.properties.telephone1;<\/p>\n<p>if (!isValid(telephone1))<\/p>\n<p>return;<\/p>\n<p>var wait = MobileCRM.UI.EntityForm.showPleaseWait(&#8220;Please wait&#8230;&#8221;);<\/p>\n<p>\/\/Entity Contact<\/p>\n<p>var entity = new MobileCRM.FetchXml.Entity(&#8220;contact&#8221;);<\/p>\n<p>entity.addAttribute(&#8220;contactid&#8221;);<\/p>\n<p>entity.filter = new MobileCRM.FetchXml.Filter();<\/p>\n<p>entity.filter.where(&#8220;parentcustomerid&#8221;, &#8220;eq&#8221;, accountId);<\/p>\n<p>entity.filter.where(&#8220;statecode&#8221;, &#8220;eq&#8221;, 0);<\/p>\n<p>\/\/ Get the Contact Records related to the Account.<\/p>\n<p>var fetch = new MobileCRM.FetchXml.Fetch(entity);<\/p>\n<p>fetch.execute(&#8220;Array&#8221;, function (results) {<\/p>\n<p>\/\/Validate Results<\/p>\n<p>if (isValid(results) &amp;&amp; results.length &gt; 0) {<\/p>\n<p>var count = results.length;<\/p>\n<p>\/\/MobileCRM.bridge.alert(count + &#8221; count&#8221;);<\/p>\n<p>for (var i = 0; i &lt; results.length; i++) {<\/p>\n<p>var contact = results[i];<\/p>\n<p>var contactId = contact[0];<\/p>\n<p>var enContact = new MobileCRM.DynamicEntity(&#8220;contact&#8221;, contactId);<\/p>\n<p>enContact.properties.telephone1 = telephone1;\u00a0 \/\/Business Phone<\/p>\n<p>\/\/Update Contact record<\/p>\n<p>enContact.save(<\/p>\n<p>function (error) {<\/p>\n<p>if (error) {<\/p>\n<p>wait.close(); \/\/ It is used to close the wait dialog<\/p>\n<p>MobileCRM.bridge.alert(functionName + &#8221; &gt;&gt; &#8221; + error);<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>count&#8211;;<\/p>\n<p>if (count &lt;= 0)<\/p>\n<p>wait.close(); \/\/ It is used to close the wait dialog<\/p>\n<p>}<\/p>\n<p>});<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>wait.close();<\/p>\n<p>}<\/p>\n<p>},<\/p>\n<p>function (err) {<\/p>\n<p>MobileCRM.bridge.alert(functionName + &#8221; &gt;&gt; &#8221; + err);<\/p>\n<p>});<\/p>\n<p>}<\/p>\n<p>});<\/p>\n<p>} catch (e) {<\/p>\n<p>MobileCRM.bridge.alert(functionName + &#8221; &gt;&gt; &#8221; + err);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>After deploying the script on <strong>Resco Mobile App<\/strong>, when the user\/technician will open an <strong>Account<\/strong> record and update \u2018Main Phone\u2019 (i.e. telelphone1), the <strong>please wait dialog<\/strong> will be displayed till the completion of process as shown in the below screenshot:<\/p>\n<p style=\"padding-left: 120px;\"><img decoding=\"async\" class=\"aligncenter wp-image-24131\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/07\/1Resco-Mobile-App.png\" alt=\"Resco Mobile App\" width=\"502\" height=\"626\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/07\/1Resco-Mobile-App.png 567w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/07\/1Resco-Mobile-App-240x300.png 240w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>In this way, by using the <strong>showPleaseWait<\/strong> JSBridge function we can add the loader on screen until the process is completed in <strong>Mobile App<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction While working with the script (using JSbridge reference) in Resco Mobile App, sometimes it takes more time to perform the operation since the process is async in the Resco Mobile app. If we want to hold the screen till the completion of process, we need to add loader or processing bar on the page\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/07\/how-to-add-loader-on-screen-in-resco-mobile-app\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":24133,"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":[18,48],"tags":[1445],"class_list":["post-24130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365-v9-2","category-resco-mobile-crm","tag-resco-mobile-app"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/24130","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=24130"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/24130\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/24133"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=24130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=24130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=24130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}