D365 Field Service: Enable lead scheduling and get location using Power Automate
Have you ever had a requirement where you needed Dynamics 365 Field Service to be able to schedule leads? This could be relevant for organizations who need their sales reps to visit prospects at their location to perform certain tasks. (I.E measurements for a project like the installation of hurricane windows or installation of flooring) The processes that I am going to configure in Dynamics 365 for this scenario will be as follows: A lead gets entered in Dynamics 365. After the lead is entered, it needs to be scheduled for an on-site visit with a sales rep. In order to be able to calculate the travel time this means that we need to capture the longitude and latitude of the lead’s address. I am going to use Power Automate and with the Bing maps connector for that.
Enable the lead table for scheduling
In order to enable the lead entity for scheduling, you need to navigate to the Resource Scheduling App. Change the area to ‘Settings’ and click on ‘Administration’ which is located under the ‘Scheduling’ section. From here you’ll see the ‘Enable Resource Scheduling for Entities’ option on the screen. Click on this option and the setup wizard window will open. This is where you can enable the entity. In the ‘Add entity’ drop down select the ‘Leads’ table/entity. Since this table hasn’t been enabled for scheduling, the booking relationship and requirement relationships don’t exist yet which means you will have to select ‘Create new relationship’ in each of those fields. Click the ‘Publish Customization’ button.
NOTE: The booking relationship and requirement relationship represent 1-to-Many relationships between the lead table and the bookable resource bookings table and between the lead table and the resource requirement table. When you click on the Publish Customization button, these relationship will be created by the system automatically.
Once the changes have been published and you refresh your screen, you will see the lead table show up under the ‘Enabled Entities’. Double click “Lead’ from the list to open the ‘Booking Setup Metadata’ record. Here you can configure a few different things. You can set the default booking duration, and the default statuses. This is also where you can enable quick book for this table. The Attribute Mapping’ section is where we map the lead fields to the requirement fields. This means when a requirement is created, it will copy these fields from the lead over to the requirement. The good news is that the lead table already has longitude and latitude fields, but if you were trying to do this for a custom table that doesn’t have those fields, you can add them yourself. Set the Latitude field to ‘Address 1: Latitude’ and the Longitude field to ‘Address 1: Longitude’.
Since I also want to show some lead related data when a lead booking is visible on the schedule board, I am going to enter this here as well.
Click on ‘Schedule Board Settings’ and copy the following into the ‘Booking Template’ field:
<div style="line-height: 11px !important; width: 99%; overflow: hidden; display: block; text-overflow: ellipsis;">
<b>{new_lead_bookableresourcebooking_new_lead.fullname} -
<b> {new_lead_bookableresourcebooking_new_lead.address1_city},
{new_lead_bookableresourcebooking_new_lead.address1_stateorprovince}</b></font>
<br/>
<b>{new_lead_bookableresourcebooking_new_lead.subject}</b></div>
NOTE: Once the lead is scheduled this code will now show the lead’s first name and last name, city and state and the data in the topic field on the on the schedule board, as shown on the below image.
Create the Power Automate flow
The next step is to create the power automate flow that will update the lead with the longitude and latitude fields once the address has been entered into the lead. Navigate to flow.microsoft.com and click ‘+Create’ on the left navigation bar and click on ‘Automated Cloud Flow’. The trigger for this flow is ‘When a record is created, updated or deleted, using the current environment connector for CDS. For the actual trigger condition I am going to select ‘Create or Update’, and obviously I am selecting ‘Leads’ as the entity/table. For scope I am setting this as ‘Organization’, but you can choose the scope that makes most sense to you. I want this to run when the address fields are entered or updated, so in the filtering attributes field I enter ‘address1_line1’. The ‘Run As’ field is set to run as the ‘triggering user’.
In the next step we’re going to use Bing Maps to get the actual location by entering the address from the lead into the step. Click ‘+New Step’ and search for ‘Bing Maps’. Select the ‘Get location by address’ action. This step will prompt you for a connection name and the API key. Information on how to get a Bing Maps key can be found here. Once you entered the connection name and API key, click on ‘create’. Once the connection is successful you can enter the dynamic data from CDS into the fields.
Click inside the ‘Address Line’ field, and search and enter ‘Street 1’ from CDS. For ‘Locality (City)’ enter ‘City’, for ‘Admin district(State)’ enter ‘State/Province’. Enter ‘Zip/Postal Code’ in the ‘Postal Code’ field and ‘USA’ for the ‘Country region’ field. Click ‘+Next Step’ and look for the ‘Update a record’ action using the current environment connector.
The Entity/Table name is ‘Leads’ and the item ID is ‘Lead’ from the dynamics content window of CDS. Click advanced options and scroll down until you see the Address 1: Latitude’ and ‘Address 1: Longitude’ fields. Click inside the Address 1: Latitude’ field and search for ‘Point Coordinates Latitude’ in the dynamic content window. Click on the value to enter it into the ‘Address 1: Latitude’ field. Do the same for the ‘Address 1: Longitude’ field. Make sure you name your flow and save and test!
I hope you enjoyed this post! Be sure to check in again next week for a new article or subscribe here to never miss another post!
Comments are Closed