Main Menu
  • Home/Blog
  • About Me
  • Speaking Events
  • Contact Me

D365 "Taylored" to you!

Using Power Virtual Agent in Dynamics 365 Sales

Posted by: Dian Taylor | on September 22, 2020

How great would it be if Dynamics 365 users would have access to a chat bot directly from a form in Dynamics 365? Think about a sales person that is working on an opportunity in Dynamics 365, and he or she has some questions that he/she wants answered while working on the opportunity, without having to navigate all over Dynamics 365? How great would it be if we could load power virtual agent into a form in dynamics 365? Is it even possible? I hadn’t tried this before, but figured since we have the ability to add web resources and iframe to forms, why not give it a shot! The answer is YES THIS IS POSSIBLE and I will explain in this article how to do this. I will use my ‘Sales Bot’ in Power Virtual Agent, and create a topic to assist the sales department. For demonstration purposes I will also create a Power Automate flow that will query CDS for answers which will be used in Power Virtual Agent to return to the user.

Scenario

In this specific scenario a sales user wants to know who the owner is for a particular account, they engage Power Virtual Agent from the opportunity form, then type in the account name after the bot asks for it. Power Virtual Agent then responds to the sales user by giving back the owning user name, email address and phone number.

Create Sales Topic in Power Virtual Agent

Obviously you need to create the bot first and topic(s). Steps on how to do that can be found here. Once the bot is created, I’m going to create a new topic which I call ‘Sales Topics’. The trigger phrases I am using are ‘Sales’ and ‘I need sales help’, I’m sure you can come up with some others too. Click ‘Save Topic’ on the top right, then click on ‘Go to authoring canvas’. The message will state:’I am the Sales Bot’ (if you don’t want a message you can delete it). I add a question that reads:’How can I help you?’. The options are very slim here, since this is just an example, you’ll be able to build additional options and logic out. My options are ‘Account’ and ‘Opportunity’. I only configured the ‘Account’ path. When the user picks ‘Account’, the next question is asking ‘Please enter the account name’, which I configure to save as the users’ entire response. I also rename the response to this question (save response as) from ‘Var’ to ‘account’. The next step is to call a power automate flow. Click on the + button and select ‘Call an Action’, then select ‘Create a flow’. This will result in power automate opening in a separate window.

Power Automate Flow

You’ll notice that flow opens up with the Power Virtual Agent template pre-loaded. In the top Power Virtual Agent action, you can add the user input which will be coming from Power Virtual Agent into flow. This will be the data the user enters when asked what the account name is. We only have to put a place holder in the (first) Power Virtual Agent action to store this data. You can do this by clicking ‘+Add and input’ and clicking on ‘Text’. You can put a short description in the field on the right of ‘input’. As you can see I entered ‘Account input’ in the field as a description.

The next step will be where I will query the CDS for the account name that the user typed into the bot. Click on ‘+New Step’ and select ‘List Records’. I am not using the current environment connector, since my bot is in a different environment than my Dynamics 365 instance. In the environment field, select the environment you want to query data for. Select ‘Accounts’ as the entity name. I only want to bring back active accounts, and I want to search for accounts that start with whatever the user typed into the bot. you can see in the image below what I put in the filter query. Note that the ‘account input’ is coming from the placeholder we created earlier which is what the user entered in the bot when it asked for an account name. You’ll also notice that I entered 1 as the top count, because I only want to bring back one record.

The next step will be a ‘Compose’ action, where I’m going to get the unique id of that one account that got returned. (You probably want to do a condition in between where you check what happens if no accounts are found) Since I want to pull out just one record, I don’t want power automate to add the ‘apply to all’ to the step, which is why I am going to use an expression here. In the Compose action, click in the input field. In the popup window switch from ‘Dynamic Content’ to ‘Expression’, enter the following expression: body(‘List_records’)[‘value’][0][‘accountid’] and click OK. The expression should now show in the ‘inputs’ field of the compose action.

Now that I have the account unique id, I want all the data stored in the fields of that account. Once I get that I want to get to the full name, email address and phone number of the user who owns that account record, and return that in Power Virtual Agent to the sales person.
Click ‘+New Step’ and select the ‘Get record’ action, this is where we will get the account record. We will use the account unique id in the previous compose step as the identifier. Select your environment, the entity name is accounts and click in the ‘Item Identifier’ field. Under Dynamic Content, click ‘outputs’ from the compose step. The next step is going to be another ‘Get Records’ step, because we are now going to look for the user record of the account owner. (Remember I need their full name, email address and phone number). Select the environment again, set ‘Users’ as the entity name. Then click in the ‘Item Identifier’ field. In the Dynamic Content area, type ‘Owner’ in the search box. Make sure you pick the ‘Owner’ field that is listed under ‘Get Record’, not ‘List Records’.

In this last step we’re going to create placeholders to store the data that we will pass back to Power Virtual Agents. This Power Virtual Agent action was already there when you opened the flow window, so no need to add it manually.
Click on ‘+Add an output’, then ‘Text’. Enter ‘Owner’ in the ‘Enter Title’ area, then select ‘Owner’ under ‘Get Record 2’.
Click on ‘+Add an output’, then ‘Text’. Enter ’email’ in the ‘Enter Title’ area, then select ‘Primary Email’ under ‘Get Record 2’.
Click on ‘+Add an output’, then ‘Text’. Enter ‘phone’ in the ‘Enter Title’ area, then select ‘home phone’ (or another phone field) under ‘Get Record 2’.
For the 4th and last output Click on ‘+Add an output’, then ‘Text’. Enter ‘account’ in the ‘Enter Title’ area, then select ‘Account Name’ under ‘Get Record 2’. Lastly give your flow a name and save and test the flow.

Create Sales Topic in Power Virtual Agent (continued)

Navigate back to Power Virtual Agent, and make sure you configure the data input from Power Virtual Agent to flow: it will show ‘input (this is what the place holder in the first step of the flow is called) gets value from’ which we want to tie to the answer of the previous question. Click on ‘Select Variable’ and select ‘account’. This means what ever the sales person types into the bot, will be what will be passed on to flow.

Lastly we need to configure the outputs from Power Automate back to Power Virtual Agent. Scroll down until you passed the Power Automate Action. You will see the Power Automate outputs on the bottom of the action. Click the + button and select ‘Show a message’. You can now put the output data from Power Automate back into the chat: Click in the message window and click on ‘Insert Variable’ to select a variable. After this you could create a loop where the bot asks the sales user if they have another question, and if they do, they will start from the top again. (This is why you want to put other options in here) Once you’re done with the topic, you need to save and publish the bot.

Add Power Virtual Agent to Form

Now that we created the bot and the topic and the logic, we can add the bot to a dynamics 365 form. There are two different ways of doing this, we can use an iframe or a web resource. If you want to use the iFrame option, all you have to do is add an iframe to the form you want to add the Power Virtual Agent to. In my example I wanted to add Power Virtual Agent to the opportunity form, but you can add it where ever you can add an iframe or a web resource. At the time that I’m writing this article you can’t do this in the new form interface (yet) so I had to configure this using the classic form editor. I first added a new section on the form, which you can do by clicking the insert tab and selecting a 1 column section.

Iframe option

Add the iframe by clicking on the ‘insert’ tab and clicking iframe. You’ll need to enter a URL. You can find the URL by navigating to https://powerva.microsoft.com/ (make sure you are in the correct environment). On the left hand side, click on ‘Publish’, then click ‘Go to channels’ and click ‘Custom Website’ on the screen. This will show an default embed code, but for the iframe we only need part of this: copy the part that is in the double quotes after ‘iframe src=’, as this is the URL to the bot. Copy the url into the url field on the iframe. Click ‘save’ and ‘publish’.

Web resource option

If you prefer to use a web resource, here are the steps to add the power virtual agent to the form by using a web resource. Add the web resource by clicking on the ‘insert’ tab and clicking web resource. Click on the lookup of the web resource field. You’ll need to create a new web resource first. Click on ‘Look up more records’ and then click the ‘New’ button. Enter a name for the web resource. Change the type field to ‘Webpage (HTML)’, then click on the text editor. You can find the html by navigating to https://powerva.microsoft.com/ (make sure you are in the correct environment). On the left hand side, click on ‘Publish’, then click ‘Go to channels’ and click ‘Custom Website’ on the screen. This will show the default embed code you can use. Save and publish the web resource. Go back to the opportunity form (add web resource screen) and fill out the remaining fields. Click ‘Ok’, ‘Save’ and ‘Publish’. After the publishing finishes you should see the chat bot on the opportunity form!

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!

Like this:

Like Loading...

Posted in Configuration, Copilot Studio (previously Power Virtual Agents), D365 Sales, Power Automate | Tags:Chat bot, chat bot in form, Form, get account, Get one record from list records, Power Virtual Agent | Comments Off on Using Power Virtual Agent in Dynamics 365 Sales

« Setup Mailbox for Automatic Case Creation in Unified Interface
Interactive Experience Dashboards »


Comments are Closed

Filter by Category

My YouTube Channel

My Microsoft Community Blog

View my blog on the Microsoft Community!

Archives

Recent Posts

  • A Deep Dive into the Case Management Agent (preview) in D365 Customer Service April 29, 2025
  • Meet the new Scheduling Operations Agent in Dynamics 365 Field Service! April 15, 2025
  • New AI Agents to close deals faster March 11, 2025
  • Custom Copilot Record Summaries in D365 Customer Service February 25, 2025
  • 2025 Wave 1: D365 Customer Service and Contact Center February 11, 2025
  • 2025 Wave 1: Dynamics 365 Sales January 28, 2025
  • Configurable Copilot Case Summaries for D365 Customer Service January 14, 2025
  • Create unique D365 views with Fetch XML Builder! December 31, 2024
  • Smart Paste and Smart Grid(search) in Model Driven Apps December 10, 2024
  • Microsoft 365 Copilot Pages December 3, 2024
  • Autonomous Agents are here! (preview) November 19, 2024
  • Extending Copilot in D365 Sales – Part 2 November 12, 2024
  • Extending Copilot in D365 Sales – Part 1 October 29, 2024
  • Building Topics with Inputs & Outputs in Copilot Studio October 22, 2024
  • Case handling time (Preview) October 8, 2024
  • Power Platform Community Conference Top Announcements October 1, 2024
  • New lead qualification experience September 10, 2024
  • Trigger Power Automate Flow from Button in Model Driven App August 20, 2024
  • 2024 Wave 2: Copilot for Service August 6, 2024
  • 2024 Wave 2: D365 Customer Service July 30, 2024
  • 2024 Wave 2: Copilot for Sales July 23, 2024
  • 2024 Wave 2: Dynamics 365 Sales July 16, 2024
  • Extend D365 Customer Service Copilot: Ask questions about your data(verse) July 2, 2024
  • Restore deleted Dataverse rows with the Recycle Bin(preview) June 25, 2024
  • Add Dataverse knowledge to a Custom Copilot using Copilot Studio June 18, 2024

Recent Comments

  • Dian Taylor on Timeline Updates
  • Sonya on Timeline Updates
  • Dian Taylor on Copilot for Dynamics 365 Sales(preview)
  • Lisa Crosbie on Copilot for Dynamics 365 Sales(preview)
  • Dian Taylor on Build Power Virtual Agent topics with GPT



© 2019: Dynamics 365 Talk, All Rights Reserved | DISCUSSION Theme by: D5 Creation | Powered by: WordPress
Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

After submission, if the URL contains ‘subscribe=success’, you have successfully subscribed! Make sure to check your email to confirm your subscription! The mail will be coming from donotreply@wordpress.com

×
%d