{"id":30442,"date":"2022-01-25T15:53:55","date_gmt":"2022-01-25T10:23:55","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=30442"},"modified":"2023-01-13T12:58:30","modified_gmt":"2023-01-13T07:28:30","slug":"execute-js-within-rules-on-the-field-service-mobile-for-dynamics-365-field-service","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/01\/execute-js-within-rules-on-the-field-service-mobile-for-dynamics-365-field-service\/","title":{"rendered":"Execute JS within rules on the Field Service Mobile for Dynamics 365 Field Service"},"content":{"rendered":"<h2><strong>Introduction:<\/strong><\/h2>\n<p style=\"text-align: justify;\">Field Service technicians use Field Service Mobile application which provides brief information related to the Work Order, Booking and Service location. And, Woodford application allows us to help customize the Field Service Mobile application based on the business requirements for each organization.<\/p>\n<p style=\"text-align: justify;\">Woodford customization application provide various ways to automate process so that technician can easily complete their tasks at the service location. For example, custom buttons on the forms\/views, using JavaScript on the forms\/views, On load\/On Change\/On Save rules etc. With latest Woodford solution version 14.2.0, we are now able to execute the JavaScript function within Rules on the form by \u201c<strong>Execute JS<\/strong>\u201d feature.<\/p>\n<p style=\"text-align: justify;\">Previously we were required to develop the JavaScript to execute the functionalities for On Change\/On Load etc. event using \u201c<strong>MobileCRM.UI.EntityForm.onChange<\/strong>\u201d functions, which further includes the code for the logic to achieve specific requirement. However, using <strong>ExecuteJS<\/strong> function we can eliminate the code for \u201c<strong>MobileCRM.UI.EntityForm.onChange<\/strong>\u201d and reuse the simple JavaScript functions within On load\/On change rules directly.<\/p>\n<p style=\"text-align: justify;\">We can add the Rules on the forms in order to automatically populate default values, hide show fields, update record values etc. But previously it was difficult to add complicated logic within Rules on the forms. Now as we have an option to execute the JS function from Rules we are not supposed to add additional Iframe on the Form in order execute JavaScript functionality.<\/p>\n<p style=\"text-align: justify;\">Now, let\u2019s consider an example where user wants to schedule an appointment for particular Account from the Field Service Mobile application by single change on the Account form. To achieve this requirement using the Execute JS feature within the Rules on the Form, follow the steps given below:<\/p>\n<p><strong>1<\/strong>. On Booking, add \u201c<strong>Schedule Appointment?<\/strong>\u201d, \u201c<strong>Next Appointment Date<\/strong>\u201d, \u201c<strong>Next Appointment End Date<\/strong>&#8221; custom fields which will be used to create a new Appointment record.<\/p>\n<p><strong>2<\/strong>. Open Woodford mobile project and navigate to the Bookable Resource Booking entity form and add these fields on the same so that technician can have access to the functionality within Field Service Mobile as shown in the below screenshot:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-30443\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/1Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg\" alt=\"Field Service Mobile for Dynamics 365 Field Service\" width=\"921\" height=\"631\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/1Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg 921w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/1Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-300x206.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/1Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-768x526.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/1Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-660x452.jpeg 660w\" sizes=\"(max-width: 921px) 100vw, 921px\" \/><\/p>\n<p><strong>3<\/strong>. On change of Schedule Appointment field value as Yes, we need to trigger a JavaScript function, which will create an Appointment record. So, will create the Iframe, JavaScript Library with below code to create an appointment and add these files in the Offline HTML.<\/p>\n<pre class=\"lang:css gutter:true start:1\">function ScheduleAppointment() {\r\ntry {\r\n\r\nMobileCRM.UI.EntityForm.requestObject(\r\n\r\nfunction (entityForm) {\r\n\r\nvar BookingEn = entityForm.entity;\r\n\r\nif (BookingEn == null || BookingEn.properties == null)\r\n\r\nreturn;\r\n\r\nvar AppointmentRequired = BookingEn.properties.new_scheduleappointment;\r\n\r\nvar WorkOrderRef = BookingEn.properties.msdyn_workorder;\r\n\r\nif (!AppointmentRequired) return;\r\n\r\n\/\/create appointment record with Service Account\r\n\r\nvar appointmentRec = new MobileCRM.DynamicEntity.createNew(\"appointment\");\r\n\r\nappointmentRec.properties.subject = \"Appointment For \" + WorkOrderRef.primaryName;\r\n\r\nappointmentRec.properties.regardingobjectid = new\u00a0 MobileCRM.Reference(BookingEn.entityName, BookingEn.id);\r\n\r\nappointmentRec.properties.scheduledstart = BookingEn.properties.new_nextappointmentdate;\r\n\r\nappointmentRec.properties.scheduledend = BookingEn.properties.new_nextappointmentenddate;\r\n\r\nappointmentRec.save(\r\n\r\nfunction (err) {\r\n\r\nif (err)\r\n\r\nMobileCRM.bridge.alert(err);\r\n\r\nelse {\r\n\r\nMobileCRM.bridge.alert(\"Appointment Scheduled Successfully...\");\r\n\r\n}\r\n\r\n}\r\n\r\n);\r\n\r\n},\r\n\r\n);\r\n\r\n}\r\n\r\ncatch (err) {\r\n\r\nMobileCRM.bridge.alert(err);\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-30444\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/2Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg\" alt=\"Field Service Mobile for Dynamics 365 Field Service\" width=\"1273\" height=\"621\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/2Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg 1273w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/2Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-300x146.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/2Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-1024x500.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/2Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-768x375.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/2Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-660x322.jpeg 660w\" sizes=\"(max-width: 1273px) 100vw, 1273px\" \/><\/p>\n<p><strong>4<\/strong>. Now add the Iframe on the Booking form using \u201c<strong>Add Iframe<\/strong>\u201d button within mobile app project as shown in the below screenshot:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-30445\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/3Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg\" alt=\"Field Service Mobile for Dynamics 365 Field Service\" width=\"1265\" height=\"649\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/3Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg 1265w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/3Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-300x154.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/3Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-1024x525.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/3Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-768x394.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/3Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-660x339.jpeg 660w\" sizes=\"(max-width: 1265px) 100vw, 1265px\" \/><\/p>\n<p><strong>5<\/strong>. Now this functionality can be triggered on change of \u201c<strong>Schedule appointment<\/strong>\u201d field on the Booking record by adding the resco rules with <strong>ExecuteJS<\/strong> function by mentioning the tab and function Name from the script.<\/p>\n<p>Please refer below screenshot for the same.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-30446\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/4Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg\" alt=\"Field Service Mobile for Dynamics 365 Field Service\" width=\"1129\" height=\"559\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/4Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg 1129w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/4Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-300x149.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/4Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-1024x507.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/4Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-768x380.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/4Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-660x327.jpeg 660w\" sizes=\"(max-width: 1129px) 100vw, 1129px\" \/><\/p>\n<p><strong>6<\/strong>. Next, save the changes and publish the customizations of the mobile project.<\/p>\n<p><strong>7<\/strong>. Technician can now open the Field Service Mobile app, navigate to the Booking Record, fill the <strong>Next Appointment Date<\/strong>, <strong>Next Appointment End Date <\/strong>and change the Schedule Appointment as Yes. This will create the appointment record with below listed details.<\/p>\n<ul>\n<li><strong>Subject<\/strong>: Appointment For &lt;&lt;Work Order Number&gt;&gt;<\/li>\n<li><strong>Regarding<\/strong>: Bookable Resource Booking record<\/li>\n<li><strong>Scheduled Start<\/strong>: Next Appointment Date on Booking<\/li>\n<li><strong>Scheduled End<\/strong>: Next Appointment End Date on Booking<\/li>\n<\/ul>\n<p>Please refer below screenshot for the same.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-30447\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/5Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg\" alt=\"Field Service Mobile for Dynamics 365 Field Service\" width=\"451\" height=\"629\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/5Field-Service-Mobile-for-Dynamics-365-Field-Service-ink.jpeg 451w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/01\/5Field-Service-Mobile-for-Dynamics-365-Field-Service-ink-215x300.jpeg 215w\" sizes=\"(max-width: 451px) 100vw, 451px\" \/><\/p>\n<h2><strong>Conclusion<\/strong>:<\/h2>\n<p style=\"text-align: justify;\">This <strong>ExecuteJS<\/strong> function within Resco rules allow us to easily execute the JavaScript functionality using simple rules instead of adding the complex code of request Objects as On load\/On change\/On save, which enhances the Field Service Mobile app functionalities.<\/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>Introduction: Field Service technicians use Field Service Mobile application which provides brief information related to the Work Order, Booking and Service location. And, Woodford application allows us to help customize the Field Service Mobile application based on the business requirements for each organization. Woodford customization application provide various ways to automate process so that technician\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/01\/execute-js-within-rules-on-the-field-service-mobile-for-dynamics-365-field-service\/\">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":[27,2361],"tags":[553,2555,2554],"class_list":["post-30442","post","type-post","status-publish","format-standard","hentry","category-field-service-2","category-technical","tag-dynamics-365-field-service","tag-execute-js","tag-field-service-mobile"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/30442","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=30442"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/30442\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=30442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=30442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=30442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}