{"id":24965,"date":"2020-10-02T11:34:47","date_gmt":"2020-10-02T11:34:47","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=24965"},"modified":"2023-01-13T14:08:18","modified_gmt":"2023-01-13T08:38:18","slug":"dynamically-filter-the-lookup-on-field-service-mobile-app","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/10\/dynamically-filter-the-lookup-on-field-service-mobile-app\/","title":{"rendered":"Dynamically filter the lookup on Field Service Mobile App"},"content":{"rendered":"<p style=\"text-align: justify;\">The Field Service Mobile app helps organizations to deliver services to customer locations. It provides the ability to work on the Bookings by the Technician i.e. Bookable Resource.<\/p>\n<p>This application includes various features to automate the process so that technicians can work efficiently and flawlessly. In this blog, we will walk through the ability to dynamically filter the lookup in the Field Service Mobile app using <strong>updateLinkItemViews<\/strong> function.<\/p>\n<p>Consider this example: we have to filter out <strong>Company Name<\/strong> lookup on Contact based on <strong>City<\/strong> field value. Therefore, whenever the <strong>City<\/strong> on the Contact form is updated, <strong>Company Name<\/strong> lookup should be filtered out with the Accounts containing <strong>City <\/strong>as City of the Contact record.<\/p>\n<p>Please find the below steps to follow to achieve our considered request:<\/p>\n<ol style=\"text-align: justify;\">\n<li>Customize contact form to include the <strong>Company Name<\/strong> (parentcustomerid) and <strong>City <\/strong>fields as shown in the below screenshot.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-24966 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-1.png\" alt=\"Dynamically filter the lookup on Field Service Mobile App\" width=\"1027\" height=\"502\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-1.png 1027w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-1-300x147.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-1-768x375.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-1-1024x501.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-1-660x323.png 660w\" sizes=\"(max-width: 1027px) 100vw, 1027px\" \/><\/a><\/li>\n<p><\/p>\n<li>Add HTML and script within Offline HTML section, this includes the logic to bind the dynamic filters to the lookup on the form.<br \/>\n<br \/>\n<strong>AccountFilter.HTML:<\/strong> This html includes reference to the Javascript file as we can add only HTML file on the form. Below is the code snippet for the same.<\/p>\n<blockquote><p>&lt;!DOCTYPE html&gt;<\/p>\n<p>&lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221;&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;title&gt;&lt;\/title&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;JSBridge.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;JSBridgeExtension.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;Schema.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;Common.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;Enums.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;Telemetry.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;FilterAccount.js&#8221; &gt;&lt;\/script&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body onload=&#8221;AccountFilter();&#8221;&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p><\/blockquote>\n<p><strong>FilterAccount.js:<\/strong>\u00a0 This includes the business logic for filtering the <strong>Company Name<\/strong> lookup based on the <strong>City<\/strong> value entered on the Contact Form. Below is the code snippet for the same.<\/p>\n<blockquote><p>function AccountFilter() {<\/p>\n<p>try {<\/p>\n<p>\/\/ Change the parent customer on currently edited contact entity<\/p>\n<p>MobileCRM.UI.EntityForm.onChange(function (entityForm) {<\/p>\n<p>if (entityForm.context.changedItem != &#8220;address1_city&#8221;) return;<\/p>\n<p>MobileCRM.UI.EntityForm.requestObject(function (entityForm) {<\/p>\n<p>\/\/ Take detail view with name &#8220;General&#8221;<\/p>\n<p>var detailsView = entityForm.getDetailView(&#8220;General&#8221;);<\/p>\n<p>var inlineSetup = new MobileCRM.UI.DetailViewItems.LookupSetup();<\/p>\n<p>var City = entityForm.entity.properties.address1_city;<\/p>\n<p>inlineSetup.addView(&#8220;account&#8221;, &#8220;Default&#8221;, true);<\/p>\n<p>\/\/ Alternatively, specify the explicit fetch XML filter for inline lookup<\/p>\n<p>inlineSetup.addFilter(&#8220;account&#8221;, &#8216;&lt;fetch version=&#8221;1.0&#8243;&gt;&lt;entity name=&#8221;account&#8221;&gt;&lt;attribute name=&#8221;name&#8221; \/&gt;&lt;attribute name=&#8221;primarycontactid&#8221; \/&gt;&lt;attribute name=&#8221;telephone1&#8243; \/&gt;&lt;attribute name=&#8221;accountid&#8221; \/&gt;&lt;order attribute=&#8221;name&#8221; descending=&#8221;false&#8221; \/&gt;&lt;filter type=&#8221;and &lt;condition attribute=&#8221;address1_city&#8221; operator=&#8221;eq&#8221; value=&#8221;&#8216; + City + &#8216;&#8221; \/&gt; &lt;condition attribute=&#8221;statecode&#8221; operator=&#8221;eq&#8221; value=&#8221;0&#8243; \/&gt;&lt;\/filter&gt;&lt;\/entity&gt;&lt;\/fetch&gt;&#8217;);<\/p>\n<p>dialogSetup = new MobileCRM.UI.DetailViewItems.LookupSetup();<\/p>\n<p>dialogSetup.addView(&#8220;account&#8221;, &#8220;Default&#8221;, true);\u00a0 \/\/ Set &#8220;Default&#8221; view for expanded lookup form<\/p>\n<p>dialogSetup.addFilter(&#8220;account&#8221;, &#8216;&lt;fetch version=&#8221;1.0&#8243;&gt;&lt;entity name=&#8221;account&#8221;&gt;&lt;attribute name=&#8221;name&#8221; \/&gt;&lt;attribute name=&#8221;primarycontactid&#8221; \/&gt;&lt;attribute name=&#8221;telephone1&#8243; \/&gt;&lt;attribute name=&#8221;accountid&#8221; \/&gt;&lt;order attribute=&#8221;name&#8221; descending=&#8221;false&#8221; \/&gt;&lt;filter type=&#8221;and &lt;condition attribute=&#8221;address1_city&#8221; operator=&#8221;eq&#8221; value=&#8221;&#8216; + City + &#8216;&#8221; \/&gt; &lt;condition attribute=&#8221;statecode&#8221; operator=&#8221;eq&#8221; value=&#8221;0&#8243; \/&gt;&lt;\/filter&gt;&lt;\/entity&gt;&lt;\/fetch&gt;&#8217;);<\/p>\n<p>dialogOnly = false; \/\/ Allow both inline lookup and expanded lookup dialog<\/p>\n<p>\/\/ Allow both inline lookup and expanded lookup dialog<\/p>\n<p>detailsView.updateLinkItemViews(0, dialogSetup, inlineSetup, dialogOnly);<\/p>\n<p>}, null, null);<\/p>\n<p>},<\/p>\n<p>function (error) {<\/p>\n<p>MobileCRM.bridge.alert(&#8220;An error occurred: &#8221; + error);<\/p>\n<p>},null);\u00a0 }<\/p>\n<p>catch (err) {<\/p>\n<p>MobileCRM.bridge.alert(err);<\/p>\n<p>}<\/p>\n<p>}<\/p><\/blockquote>\n<\/li>\n<li>Once completed with adding offline html, we need to include the <strong>AccountFilter.html<\/strong> file on the Contact Form by adding an Iframe as shown in the below screenshot.<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-2.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-24967 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-2.png\" alt=\"Dynamically filter the lookup on Field Service Mobile App\" width=\"732\" height=\"493\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-2.png 732w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-2-300x202.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-2-660x445.png 660w\" sizes=\"(max-width: 732px) 100vw, 732px\" \/><\/a><\/li>\n<p><\/p>\n<li>Save and close the form and Publish the Mobile project to reflect the customizations in the Field Service Mobile App.<\/li>\n<li>Now Sync the Field Service Mobile app and navigate to the Contact record. Change the <strong>City<\/strong> on the contact and click on the <strong>Company Name<\/strong> lookup. This will filter and display the accounts containing the <strong>City<\/strong> as that of the City of the contact.As shown in the below screenshot, we have added <strong>City<\/strong> as <strong>Clinton<\/strong> then the Company Name lookup will filter the accounts containing the <strong>City<\/strong> as <strong>Clinton<\/strong>.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-3.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-24968\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-3.png\" alt=\"Dynamically filter the lookup on Field Service Mobile App\" width=\"735\" height=\"435\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-3.png 735w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-3-300x178.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/10\/Dynamically-filter-the-lookup-on-Field-Service-Mobile-App-3-660x391.png 660w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><\/a><\/li>\n<\/ol>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p style=\"text-align: justify;\">Field Service provides us the flexibility to achieve our business requirements by filtering lookups using <strong>updateLinkItemViews<\/strong> function within Field Service Mobile App.<\/p>\n<h3 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">Need any help with Microsoft Dynamics 365 Field Service module \/ Microsoft CRM \/ Power Platform development?<\/div><\/div><\/h3>\n<p><em>Want to manage your field services portal more effectively? Contact us at <a href=\"mailto:crm@inogic.com\" target=\"_blank\" rel=\"noopener\">crm@inogic.com<\/a> and our <a href=\"https:\/\/bit.ly\/3VvGawa\" target=\"_blank\" rel=\"noopener\">Inogic- Professional Services Division<\/a> will help you modify, optimize, and automate all our requirements within Microsoft Dynamics 365 Field Service!<\/em><\/p>\n<p><em>Happy Servicing!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Field Service Mobile app helps organizations to deliver services to customer locations. It provides the ability to work on the Bookings by the Technician i.e. Bookable Resource. This application includes various features to automate the process so that technicians can work efficiently and flawlessly. In this blog, we will walk through the ability to\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/10\/dynamically-filter-the-lookup-on-field-service-mobile-app\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"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":[16,19,27],"tags":[2079,545,2020,1978,1890],"class_list":["post-24965","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm","category-field-service-2","tag-dynamic-filter","tag-dynamics-365-crm","tag-dynamics-365-crm-field-service-mobile-app","tag-dynamics-365-field-service-mobile-app","tag-field-service-mobile-app"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/24965","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=24965"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/24965\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=24965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=24965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=24965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}