{"id":35913,"date":"2023-09-06T12:16:48","date_gmt":"2023-09-06T06:46:48","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=35913"},"modified":"2023-09-07T10:17:34","modified_gmt":"2023-09-07T04:47:34","slug":"execute-ssrs-report-using-javascript-in-dynamics-365-field-service-mobile-app","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2023\/09\/execute-ssrs-report-using-javascript-in-dynamics-365-field-service-mobile-app\/","title":{"rendered":"Execute SSRS report using JavaScript in Dynamics 365 Field Service Mobile App"},"content":{"rendered":"<p><a href=\"https:\/\/www.inogic.com\/services\/techno-functional-consulting\/microsoft-dynamics-365-crm-field-service\/\" target=\"_blank\" rel=\"noopener\">Microsoft\u2019s Dynamics 365 Field Service Mobile app<\/a> provides the ability to work on tasks and resolve issues from the mobile platform in online and offline modes. The technician can view their daily schedule, which includes details such as customer names, addresses, and appointment times.<\/p>\n<p>They can see the priority of each service call, helping them prioritize urgent repairs. Before arriving at a customer&#8217;s location, the technician can access detailed customer information, including contact details and a history of previous service calls.<\/p>\n<p>From the web, we can run an SSRS Report for a record by the <strong>Run Report<\/strong> button but on the mobile <strong>Run Report<\/strong> button is not visible.<\/p>\n<p>Here comes one scenario if the technician arrives at the customer location and wants to run a report related to any record from the Mobile App, Microsoft has provided a way to show Reports on the Mobile App that is by PCF control \u201c<strong>Technician Service Reports<\/strong>\u201d.<\/p>\n<p>Refer to the below link for more details,<\/p>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/dynamics365\/field-service\/mobile-powerapp-reporting\" target=\"_blank\" rel=\"noopener\">https:\/\/learn.microsoft.com\/en-us\/dynamics365\/field-service\/mobile-powerapp-reporting<\/a><\/p>\n<p>Using this way, we can add a <strong>Report<\/strong> button on the form which will be visible on the Mobile App. But what if we want to run multiple reports from the mobile app, in this case, we need to add multiple Buttons with\u00a0 Multiple PCF controls which will be a very time-consuming and inappropriate way.<\/p>\n<p>So there is one workaround for this, we can add a functionality to show SSRS reports using JavaScript on the form without adding a button.<\/p>\n<p>This workaround allows users to access and view relevant reports directly within the form in the Mobile App, which will help streamline decision-making and enhance efficiency.<\/p>\n<p><strong><em>NOTE: This functionality will work on Mobile App online mode and Mobile App Offline mode with network connectivity.<\/em><\/strong><\/p>\n<p>In this blog, we are taking an example of a Work Order Entity to show Reports on form,<\/p>\n<p>To achieve this, We can develop a Javascript library and we can add a dynamic option set field to the Work Order form. This field contains the Names and IDs of various reports. The purpose of adding the names and IDs of the reports on the field\u2019s Label is we can use those values in the Javascript code to execute the report from the server.<\/p>\n<p>We could store Names and IDs in the value of the Option set field but there are OOB limitations that the Optionset field\u2019s value contains only Numbers. So, we need to store the Names and IDs on the field\u2019s Label.<\/p>\n<p>By selecting a report from the dropdown, users can instantly view the desired report&#8217;s content within the form.<\/p>\n<p><strong>Check the steps to achieve the same:<\/strong><\/p>\n<p><strong>Step 1<\/strong>:<\/p>\n<p>First, we can add one Option Set field with the appropriate name on the form. As below, we have added one Option Set field named <strong>Reports<\/strong>. On a field, we can add the Names and IDs of the reports that we want to see on the form.<\/p>\n<p>We required the Name and ID of the report separately to use within the code for further functionality, so will be separating the Names and IDs with a colon(:), We will check the use of the same later within the next step.<\/p>\n<p><strong><em>Note<\/em><\/strong><em>:- We need to take the Names and IDs of the Reports from the URL of the Report as shown in the below screenshots<\/em><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-35919\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/1JavaScript-in-Field-Service.jpeg\" alt=\"JavaScript in Field Service\" width=\"1429\" height=\"721\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/1JavaScript-in-Field-Service.jpeg 1429w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/1JavaScript-in-Field-Service-300x151.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/1JavaScript-in-Field-Service-1024x517.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/1JavaScript-in-Field-Service-768x387.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/1JavaScript-in-Field-Service-660x333.jpeg 660w\" sizes=\"(max-width: 1429px) 100vw, 1429px\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-35918\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/2JavaScript-in-Field-Service.jpeg\" alt=\"JavaScript in Field Service\" width=\"1429\" height=\"719\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/2JavaScript-in-Field-Service.jpeg 1429w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/2JavaScript-in-Field-Service-300x151.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/2JavaScript-in-Field-Service-1024x515.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/2JavaScript-in-Field-Service-768x386.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/2JavaScript-in-Field-Service-660x332.jpeg 660w\" sizes=\"(max-width: 1429px) 100vw, 1429px\" \/><\/p>\n<p>As we can see the Name of the Report on the URL contains (%20) in between, which is nothing but the space between the two words, We need to replace those \u201c%20\u201d with space before adding it to the field.<\/p>\n<p>We will be adding the Name and ID of the report we got from the URL on the <strong>Reports<\/strong> option set field which will be visible as shown in the below screenshot,<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-35917\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/3JavaScript-in-Field-Service.jpeg\" alt=\"JavaScript in Field Service\" width=\"1428\" height=\"637\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/3JavaScript-in-Field-Service.jpeg 1428w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/3JavaScript-in-Field-Service-300x134.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/3JavaScript-in-Field-Service-1024x457.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/3JavaScript-in-Field-Service-768x343.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/3JavaScript-in-Field-Service-660x294.jpeg 660w\" sizes=\"(max-width: 1428px) 100vw, 1428px\" \/><\/p>\n<p><strong>\u00a0<\/strong><strong>Step\u00a0 2:<\/strong><\/p>\n<p>We will show the report with the help of a report\u2019s URL so we can add an Iframe on the form and in Javascript code we will overwrite that Iframe source with the Report URL source.<strong>\u00a0<\/strong><\/p>\n<p><a href=\"https:\/\/www.maplytics.com\/blog\/category\/field-service\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone size-full wp-image-35922\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/Maplytics-A-Powerful-Tool-for-Scheduling-Tracking-and-Managing-Field-Service.gif\" alt=\"Maplytics A Powerful Tool for Scheduling Tracking and Managing Field Service\" width=\"700\" height=\"200\" \/><\/a><\/p>\n<p><strong>Step\u00a0 3:<\/strong><\/p>\n<p>We will develop a javascript code to achieve the functionality to show reports on the form.<\/p>\n<p>We will be adding this javascript library on the change event of the \u201cReports\u201d field so that when we change the value of the Report field will check and show the report as per the selected value within the Iframe.<\/p>\n<pre class=\"lang:css gutter:true start:1\">var workOrderId = formContext.data.entity.getId(); \/\/ get work order Id\r\n\r\nvar reports = formcontext.getAttribute(\"new_reports\").getValue();\r\n\r\n\u00a0\r\n\r\nreports = reports.split(\":\");\r\n\r\nvar name = reports [0];\r\n\r\nvar reportId = reports [1];\r\n\r\n\/\/ get url of current organization\r\n\r\nvar url =\u00a0 Xrm.Utility.getGlobalContext().getClientUrl() ;\r\n\r\n\u00a0\r\n\r\nreportName = url + \"\/crmreports\/viewer\/viewer.aspx?id=\" + reportId + \"&amp;action=run&amp;context=records&amp;recordstype=10937&amp;records=\"\r\n\r\n+ workOrderId + \"&amp;helpID=\" + name + \".rdl\";\r\n\r\n\u00a0\r\n\r\ntabObj =\u00a0 formContext.ui.tabs.get(\"tab_Report\");\r\n\r\n\u00a0\r\n\r\n\/\/ getting IFrame\r\n\r\nvar getIframe = formContext.ui.controls.get(\"WebResource_showReportOnFSM\");\r\n\r\nvar target = reportName;\r\n\r\n\/\/show report\r\n\r\ngetIframe.setSrc(target);<\/pre>\n<p>Below is the explanation of the above code,<\/p>\n<ul>\n<li>As we can see in the above code we have separated the value of the Reports field using the Split() to get the Name and ID of the selected Report.<\/li>\n<li>We need to retrieve the URL of the current organization which we can use to put on the dynamic report\u2019s URL (Xrm.Utility.getGlobalContext().getClientUrl())<\/li>\n<li>Now construct a reportName URL, which will be a URL for viewing a report based on the url (URL of the current organization), reportId(Report\u2019s ID), workOrderId(Work Order ID), and name(Report\u2019s name).<\/li>\n<li>To generate the report URL we need some content from the original report URL.<\/li>\n<\/ul>\n<p>Please refer below screenshot for the same.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-35916\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/4JavaScript-in-Field-Service.jpeg\" alt=\"JavaScript in Field Service\" width=\"1426\" height=\"724\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/4JavaScript-in-Field-Service.jpeg 1426w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/4JavaScript-in-Field-Service-300x152.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/4JavaScript-in-Field-Service-1024x520.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/4JavaScript-in-Field-Service-768x390.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/4JavaScript-in-Field-Service-660x335.jpeg 660w\" sizes=\"(max-width: 1426px) 100vw, 1426px\" \/><\/p>\n<ul>\n<li>Now we need to copy the URL of the report and replace some parts with the dynamic values that are URL, reportId, workOrderId, and name.<\/li>\n<li>We will retrieve the Iframe we have added to show the report.<\/li>\n<li>After getting the Iframe we can overwrite the Iframe source with the Report URL source.<\/li>\n<\/ul>\n<pre class=\"lang:css gutter:true start:1\">target = reportName;\r\n\r\n\/\/show report\r\n\r\ngetIframe.setSrc(target);<\/pre>\n<p>Note: The \u201c<strong>recordstype\u201d<\/strong> of the report URL will change as per the organization, so if we are moving this javascript library from organizations then we need to change the \u201crecordstype\u201d of the report URL as per the organization in the Javascript library.<\/p>\n<p>(url + &#8220;\/crmreports\/viewer\/viewer.aspx?id=&#8221; + reportId + &#8220;&amp;action=run&amp;context =records&amp;<strong>recordstype =10937<\/strong>&amp;records=&#8221;+ workOrderId + &#8220;&amp;helpID=&#8221; + name + &#8220;.rdl&#8221;)<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-35915\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/5JavaScript-in-Field-Service.jpeg\" alt=\"JavaScript in Field Service\" width=\"1430\" height=\"722\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/5JavaScript-in-Field-Service.jpeg 1430w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/5JavaScript-in-Field-Service-300x151.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/5JavaScript-in-Field-Service-1024x517.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/5JavaScript-in-Field-Service-768x388.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/5JavaScript-in-Field-Service-660x333.jpeg 660w\" sizes=\"(max-width: 1430px) 100vw, 1430px\" \/><\/p>\n<p>Now let&#8217;s check the output of the above functionality in the mobile app, Below is the screenshot of the output we got in the mobile app,<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-35914\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/6JavaScript-in-Field-Service.jpeg\" alt=\"JavaScript in Field Service\" width=\"469\" height=\"1032\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/6JavaScript-in-Field-Service.jpeg 469w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/6JavaScript-in-Field-Service-136x300.jpeg 136w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/09\/6JavaScript-in-Field-Service-465x1024.jpeg 465w\" sizes=\"(max-width: 469px) 100vw, 469px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>The integration of dynamic report display functionality within forms can significantly improve the user experience of running multiple reports for a single record. This approach allows users to access information more efficiently and contributes to informed decision-making.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft\u2019s Dynamics 365 Field Service Mobile app provides the ability to work on tasks and resolve issues from the mobile platform in online and offline modes. The technician can view their daily schedule, which includes details such as customer names, addresses, and appointment times. They can see the priority of each service call, helping them\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2023\/09\/execute-ssrs-report-using-javascript-in-dynamics-365-field-service-mobile-app\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":11,"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,27,2361],"tags":[805],"class_list":["post-35913","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-field-service-2","category-technical","tag-field-service"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/35913","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\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=35913"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/35913\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=35913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=35913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=35913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}