Track the last time someone spoke with a lead/contact in Dynamics 365

Today I am going to discuss some functionality which I believe to be very relevant in Dynamics 365. How great would it be if organizations would be able to run a query showing them all the leads or contacts in the system that they have had a conversation with in the past X months? Or maybe a list of leads or contacts that no one has spoken with at all?! If we would track this information we would be able to utilize the out of the box dynamic Marketing lists where these records would just drop in and out of, based on the conversations sales rep did or didn’t have with them! Interested? Keep reading!

Custom Fields

This functionality was something that I built out before Power Automate existed using the out of the box workflow engine in Dynamics 365. Since we now have the ability to move our workflows to Power Automate I will be recreating this logic in a Power Automate flow. Before I start building out the flow, I first need to add two custom fields to the contact and lead entity/table Dynamics 365 so I can store the relevant data:

Last spoke with: This is a date field that will automatically be populated by the flow when a phone call is marked as completed. We also want to make sure the ‘left voicemail’ field is set to ‘No’. This of course is optional, but I don’t consider leaving a voicemail as having a conversation, which is why I included this in the logic.
– Last spoke with rep: This is a lookup field to a user record. Besides knowing the date the last conversation took place, I also want to track who the sales rep was that spoke with the lead or contact on that date.

If a call is regarding a lead, I need the flow to update the ‘last spoke with’ date field on the lead (or contact) with the completion date of the phone call. I can get this from the ‘modified on’ field on the phone call record. I also need to populate the user (lookup) field ‘last spoke with rep’ on the lead with the user who closed the phone call. I can get that information from the ‘modified by’ field on the phone call. The same logic goes for a contact. Now let’s take a look on how to build the flow in Power Automate.

Flow Configuration

Navigate to Power Automate and click ‘+New Flow’, select ‘Automated Cloud Flow’. Remember we want this to automatically run when a phone call is completed (and make sure the ‘left voicemail’ field is set to ‘No’. For the trigger I select ‘When a record is created, updates of deleted’ using the common data service(current environment’ connector. The trigger condition is ‘Update’ and the entity name/table name is ‘Phone Calls’. In the advanced options I have set the scope to organization and I am running this flow as a process owner but obviously this is a personal choice. For the filter expression I am using statecode eq 1 and leftvoicemail eq false. (State code 1 = Completed). In the next step we’re going to get the phone call record, as we need to see what entity/table is in the regarding field. I tried this without getting the phone call record, but the trigger is not passing through enough information, which is why I am adding the ‘Get a record’ step. The entity/table name is ‘Phone Calls’ and the item ID is ‘phone call’ which we get from the trigger. In the below screenshot you can see the what the configuration should look like at this point.

In the next step we could probably do a condition to see which entity type/table is populated in the regarding field, but I think using the ‘Switch’ step is a lot easier. Click ‘+New Step’ and search for ‘Switch’. in the ‘On’ field you need to select the ‘Regarding(Type)’ field from the previous ‘Get a record’ step. As mentioned before, if you try to use the field from the trigger there won’t be any data passed through and your flow will fail.
You will notice there is box called ‘Case’ below the ‘Switch’ step. This represents the different outcomes (cases) of the regarding field, meaning the different entities/tables that could be set in the regarding field. (A phone call can be set regarding many different entities, I.E. leads, contacts, opportunities, cases, etc.)
Type ‘contact’ in the ‘Equals’ field. This represents the steps the flow will follow if the phone call is set regarding a contact. Click ‘Add an action’ and select ‘Update a record’. We will use this step to populate data in our custom Last Spoke With fields. Select ‘contacts’ as the entity name, and set the ‘Regarding(value)’ field from the ‘Get Record’ step as the Item ID. Expand the ‘Advanced Options’ and find the ‘Last spoke with’ field. Click your mouse in the field and from the Dynamics Content window select ‘Modified On’ from the ‘Get a record’ step. For the ‘Last Spoke With Rep’ field, type in systemusers( then enter the ‘Modified By(Value)’ field from the ‘Get Record’ step. Make sure you add a closing bracket!

Now we need to add the logic for when the phone call is regarding a case. Click on the ‘+’ button to add a case statement. Type ‘lead’ in the required ‘Equals’ field of the case. This represents the logic the flow will find if a lead record is populated in the ‘regarding’ field of the phone call record. Click ‘Add an action’ and select ‘Update a record’. We will use this step to populate data in our custom Last Spoke With fields. Select ‘leads’ as the entity name, and set the ‘Regarding(value)’ field from the ‘Get Record’ step as the Item ID. Expand the ‘Advanced Options’ and find the ‘Last spoke with’ field. Click your mouse in the field and from the Dynamics Content window select ‘Modified On’ from the ‘Get a record’ step. For the ‘Last Spoke With Rep’ field, type in systemusers( then enter the ‘Modified By(Value)’ field from the ‘Get Record’ step. Make sure you add a closing bracket!

TIP: You could also roll these values up to the account record by adding logic that will check to see if the contact is related to an account or not. If it is, the flow can update the last spoke with fields on the account as well.

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!

Share this!

Comments are Closed