{"id":24405,"date":"2020-08-14T13:29:05","date_gmt":"2020-08-14T13:29:05","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=24405"},"modified":"2020-08-14T13:29:05","modified_gmt":"2020-08-14T13:29:05","slug":"how-to-work-with-combined-filters-of-fetch-function-in-resco-mobile-app","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/08\/how-to-work-with-combined-filters-of-fetch-function-in-resco-mobile-app\/","title":{"rendered":"How to work with Combined Filters of Fetch Function in Resco Mobile App"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>Recently, we had a business requirement where we had to retrieve entity records by satisfying a combination of conditions in the script and perform operations on them in Resco Mobile App.<\/p>\n<p>For example, on <strong>Account<\/strong> entity form we added a custom button. And on click of that button we wanted to retrieve active <strong>Work Order <\/strong>records associated with that <strong>Account <\/strong>having \u2018System Status = Open \u2013 Unscheduled\u2019 and \u2018Work Order Type = Maintenance \/ Inspection\u2019 and populate \u2018Work Order Instructions\u2019 on them from the <strong>Account <\/strong>record.<\/p>\n<p>So first, we added a custom button \u2018Process Work Orders\u2019 on the <strong>Account <\/strong>entity form and then added a HTML File in \u2018Offline HTML\u2019 of Resco Project with below code snippet.<\/p>\n<p>Code Snippet:<\/p>\n<p>\/\/Event of CustomCommand<\/p>\n<p>MobileCRM.UI.EntityForm.onCommand(&#8220;custom_ProcessWorkOrders&#8221;, function (entityForm) {<\/p>\n<p>\/\/FetchXML Entity for retrieving Work Order records<\/p>\n<p>var entity = new MobileCRM.FetchXml.Entity(&#8220;msdyn_workorder&#8221;);<\/p>\n<p>entity.addAttribute(&#8220;msdyn_workorderid&#8221;);<\/p>\n<p>entity.addAttribute(&#8220;msdyn_name&#8221;);<\/p>\n<p>\/\/Sub filter with AND clause<\/p>\n<p>var subFilter1 = new MobileCRM.FetchXml.Filter();<\/p>\n<p>subFilter1.type = &#8220;and&#8221;;<\/p>\n<p>subFilter1.where(&#8220;msdyn_serviceaccount&#8221;, &#8220;eq&#8221;, entityForm.entity.id); \/\/Service Account<\/p>\n<p>subFilter1.where(&#8220;msdyn_systemstatus&#8221;, &#8220;eq&#8221;, 690970000); \/\/Open &#8211; Unscheduled<\/p>\n<p>subFilter1.where(&#8220;statecode&#8221;, &#8220;eq&#8221;, 0); \/\/Active<\/p>\n<p>\/\/Sub filter with OR clause<\/p>\n<p>var subFilter2 = new MobileCRM.FetchXml.Filter();<\/p>\n<p>subFilter2.type = &#8220;or&#8221;;<\/p>\n<p>subFilter2.where(&#8220;msdyn_workordertype&#8221;, &#8220;eq&#8221;, &#8220;ad2d8b0a-2fe7-e611-8110-e0071b66bf01&#8221;); \/\/Inspection<\/p>\n<p>subFilter2.where(&#8220;msdyn_workordertype&#8221;, &#8220;eq&#8221;, &#8220;69a69cba-bad3-ea11-a812-000d3a569dff&#8221;); \/\/Maintenance<\/p>\n<p>\/\/Main Filter i.e. group of subfilters<\/p>\n<p>var mainFilter = new MobileCRM.FetchXml.Filter();<\/p>\n<p>mainFilter.type = &#8220;and&#8221;;<\/p>\n<p>mainFilter.filters = [subFilter1, subFilter2]; \/\/sub filters<\/p>\n<p>\/\/Add Main Filter in Entity Filter<\/p>\n<p>entity.filter = mainFilter;<\/p>\n<p>var fetch = new MobileCRM.FetchXml.Fetch(entity);<\/p>\n<p>\/\/fetching data of entity<\/p>\n<p>fetch.execute(&#8220;DynamicEntities&#8221;, function (result) {<\/p>\n<p>\/\/validate result<\/p>\n<p>if (typeof (result) != &#8220;undefined&#8221; &amp;&amp; result.length &gt; 0) {<\/p>\n<p>\/\/Here you can perform operation on the retireve records.<\/p>\n<p>\/\/You will get the retrieved records in the \u201cresult\u201d object<\/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>});<\/p>\n<p><strong>Note: We need to add all \u2018sub filters\u2019 in the \u2018main filter\u2019 and then associate that \u2018main filter\u2019 to the \u2018FetchXML Filter\u2019 to make it work.<\/strong><\/p>\n<p style=\"text-align: justify;\">Next, we added this Html file in the \u2018Iframe\u2019 of the <strong>Account <\/strong>entity form and published the Resco Project. Then after publishing Resco Project we synced the Resco Mobile App with that environment and navigated to the <strong>Account <\/strong>record. Next, we clicked on the \u2018Process Work Orders\u2019 for retrieveing and updating the <strong>Work<\/strong> <strong>Order<\/strong> records based on the conditions.<\/p>\n<p>Now after the execution of this function, only the active <strong>Work Order <\/strong>records associated with that <strong>Account <\/strong>having \u2018System Status = Open \u2013 Unscheduled\u2019 and \u2018Work Order Type = Maintenance \/ Inspection\u2019 was retrieved and processed.<\/p>\n<p>Please refer below screenshot:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-24406\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/08\/Resco.png\" alt=\"Resco\" width=\"1366\" height=\"701\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/08\/Resco.png 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/08\/Resco-300x154.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/08\/Resco-768x394.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/08\/Resco-1024x525.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/08\/Resco-660x339.png 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>In this way, instead of performing multiple Fetch Functions or Fetch XML for retrieving entity records of the same entity, we can use <strong>\u2018Combined Filter\u2019<\/strong> in a single Fetch Function for retrieving the records of same entity based on multiple conditions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Recently, we had a business requirement where we had to retrieve entity records by satisfying a combination of conditions in the script and perform operations on them in Resco Mobile App. For example, on Account entity form we added a custom button. And on click of that button we wanted to retrieve active Work\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/08\/how-to-work-with-combined-filters-of-fetch-function-in-resco-mobile-app\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":24407,"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],"tags":[1445],"class_list":["post-24405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-resco-mobile-crm","tag-resco-mobile-app"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/24405","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=24405"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/24405\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/24407"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=24405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=24405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=24405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}