Extending Copilot in D365 Sales – Part 1

You have most likely heard of all the different Copilots that Microsoft published in the past year, from Copilot in Microsoft Teams to Copilot in SharePoint, Dynamics 365 apps and of course Microsoft 365 Copilot which is grounded in business data, allowing users to ask questions about work related things. In this article I am going to discuss how we can extend Copilot in Dynamics 365 Sales. Just to be clear, I am not talking about Copilot for Sales, which requires an additional license and which can be connected to D365 Sales or Sales Force, I am referring to the Copilot that lives inside of Dynamics 365 Sales. It is also possible to extend Copilot for Sales, but I found this to be more complicated and most likely you will need the help of a developer. If you’ve worked with Dynamics 365 Sales before, you probably have worked with Copilot in Dynamics 365 Sales. Out of the box this Copilot empowers sellers with quick access to sales data from Dynamics 365, from providing account news to interacting with SharePoint documents. Copilot helps streamline tasks like reviewing sales record updates and preparing for meetings right within Dynamics 365 Sales. By extending Copilot in Dynamics 365 Sales, businesses can tailor Copilot’s capabilities to meet business needs. This can include integrating Copilot with other systems to access external data sources and facilitate actions such as asking questions and creating or updating records in those systems.

Configuration Options

There are a few different options when we’re talking about extending Copilot in D365 Sales. For example, we can add topics, knowledge and actions but we also have access to configure the ‘View Prompts’ (aka sparkle) menu. In this article I will be focusing on the ability to create an action in Copilot in Dynamics 365 Sales, and then calling that action from within a topic. In next week’s article I will be focusing on how to configure the ‘View Prompts’ menu so make sure you check back next week!

Scenario

Since I don’t have other systems to connect Copilot in Dynamics 365 Sales to, I am going to add a topic that will allow sellers to create a new case in Dynamics 365. I will do this by creating an action from a power automate flow, after which I will create a new topic that will call the action. I will allow users to use this prompt from within the context of a contact record, which will allow copilot to capture the contact id, which we will use in the action to create a case. The case will be tied to the account the contact is related to and will populate the contact on the case as well. I hope this example will show you how powerful this functionality is!

Create the action

First, I need to open the ‘Sales Copilot Power Virtual Agents Bot’ in Copilot Studio. This is the name of Copilot in Dynamics 365 Sales. I navigate to Copilot Studio by entering https://copilotstudio.microsoft.com/ in the browser. Please make sure the correct environment is selected in the environment picker. If you have built Agents with Copilot Studio before, this will be a piece of cake! You’ll be able to add topics and actions just like you are able to do in custom copilots (aka Agents). Navigate to ‘Actions’ to start the process to create the action. I click the ‘Add an action’ button and scroll all the way down until I see the ‘Create a new flow’ button. Clicking this button will take me to a window from where I can create a new Power Automate flow. The power automate flow I am going to create for this example will do the following: It will get the unique id from a contact record in Dynamics 365 sales which it will use to find the contact and associated account row, then it will create a case using a short phrase as the topic, it will set the account as the customer and it will set the contact as the case contact. When the power automate flow page opens, I notice the trigger that is used is ‘Run a flow from Copilot’. I click on the trigger and add two text inputs called ‘Contact ID’ and ‘Case Description’. I click on the + button and select ‘Add an action’. I search for the ‘Get a row by id’ from Microsoft Dataverse. For the table name I select ‘Contacts’ and for the row id I selected the previously created input called ‘contact id’. I expand the advanced parameters and enter ‘parentcustomerid_account($select=accountid)’ in the ‘Expand Query’ field. This will allow me to get data from the account related to the contact record, which I will need in order to set the account record as the customer. You probably should enter a condition on what should happen if the contact isn’t associated to an account record, which I will not do for this example. I click the + button again, select add an action and search for and select the ‘Add a row’ action from the Dataverse connector. In this step I will create a new case and connect it to the account and contact rows. I select ‘Cases’ as the table name, then in the ‘Case Title’ field I click on the lightning icon and enter the previously created input ‘Case Description’. Under ‘Customer(accounts)’ column I enter ‘accounts/‘ and I click on the lightning icon on the right side of the column. I enter ‘Account’ in the search bar and select ‘Account(Value)’ under ‘Get a row by ID’. Make sure you pick the one that has the description: ‘Select the parent account or parent contact for the contact to provide…”.

I scroll down until I get to the ‘Contact(Contacts)’ column, and enter ‘contacts/’, then I click on the lightning icon on the right side of the column and search for ‘Contact’ (I’m looking for the unique identifier or the contact row to tie the case to. Lastly in the ‘Respond to Copilot’ step I add another text output, where I enter the dynamic value ‘Case Number’ from the ‘Add a new row’ step. This will allow me to feed the case number back into the chat. I enter the name ‘Copilot: Create case from contact id’ in the top left corner and save the Power Automate flow. I go back to Copilot and click on the ‘Refresh’ button. Now I select my newly created flow called ‘Copilot: Create case from contact id’, I click the ‘Next’ button twice, until I get to the third screen, titled ‘Step 3 of 3: Review and Finish’. I click ‘Edit’ next to ‘Configure’ and below ‘Selected Action’ . In the ‘Description for the copilot to know when to use this action’ I enter ‘This action is used to create a case.’, then I click ‘Back’ and then ‘Finish’. This creates the action in Copilot Studio.

Pass contact id to the action

I’ve you’ve used Copilot in D365 Sales before, then you might have noticed that Copilot is able to recognize the context of a record when a prompt is used. Think about when it summarizes records (leads, opportunities, accounts), for example, when an opportunity or lead is opened in the Sales Hub with the Copilot sidecar expanded, it will automatically summarize the opportunity row the user opened (if Copilot is configured to do so.) Copilot knows the unique id of the opportunity or lead that it needs to summarize as the record id is stored in a global variable that is passed through to Copilot. To pass the record ID in the action I just created, I’ll need to configure this, so I click on the action to open it.

I click on ‘Inputs’ and I change the ‘How will copilot fill this input?’ for the ‘ContactID’ input to ‘Set as a value’. You’ll notice that the field below it now changes to ‘Value’. I click on the arrow on the right side of the field and search for ‘Context.id.guid‘. This brings up the variable ‘Global.PA__Copilot_Model_PageContext.pageContext.id.guid‘, which is the variable that holds the id of the record that shows on the page in Dynamics 365 Sales. Keep in mind that my Power Automate Flow extracts the contact ID and from there finds the associated account, so I have to make sure I enter a condition that will only allow for this action to run when the user is on a contact record!

Create a new topic

First I am going to add a new topic by navigating to topics and clicking the ‘Add a Topic’ > ‘from blank’ buttons. I enter several phrases, which a user can enter to call this topic. I enter: ‘Create a case, create a ticket, and add case’. Below the trigger I click on the ‘+ sign’ and select ‘add a condition’. This is where I need to make sure the action will only run for contact records. I click on the arrow on the right side of ‘Select a variable’ and I am looking for the ‘Global.PA__Copilot_Model_PageContext.pageContext.entityTypeName‘ variable. This variable holds the entity/table name that the seller has open when entering the prompt in Copilot. Since I only want this to work for the contact table, I enter ‘is equal to’ and below that I enter ‘contact’ (no caps!). Since I ONLY want this to run when a contact record is opened, I need to add a second (and) condition. I click on the ‘New Condition’ button that is visible in the condition node I just created and click on the arrow on the right side of the field ‘Select a variable’ to see the list of variables.

Here I select the variable called ‘Global.PA__Copilot_Model_PageContext.pageContext.id.guid‘ again. I select ‘is not blank’ as the condition. This will make sure a contact record is selected and the unique id (guid) can be passed through to the action. Below the condition, I add a question: ‘Please enter the case description’, which will be used as the Case Topic when the new case is created. I change the variable name from ‘Var1’ to ‘CaseDescription’. I click on the ‘+ button’ again and select ‘Call an Action’, then I click on the arrow, which opens a new window, from there I click on ‘Plugin(preview)’ and I select the previously created action, called ‘Copilot: Create case from contact id’. Below the action I add a message where I enter ‘A new case has been created. The case id is:‘ followed by the case_id variable (which represents the case number of the newly created case). The last step is to end the current topic, and to publish! Once the copilot is published you can try it out inside Dynamics 365 Sales! I hope you enjoyed this article! Be sure to check in again next week as I discuss how we can modify the ‘View Prompt’ menu! As an example I will add a menu item called ‘Create Records’ with the ‘Create case’ prompt, which will automatically run the topic I created in this article! Feel free to subscribe here to never miss another post!

Share this!

Comments are Closed