Exercise - Create a flow with the embedded flow experience

Completed

In this exercise, you'll set up the chatbot to interact with the Dataverse for Teams tables that you created in a previous lab in this learning path. Your goal is to make sure that the user can submit a request for swag by using the chatbot. To do so, you'll use the embedded flow experience inside the Power Virtual Agents app in Teams.

Task: Get the schema name for your Dataverse for Teams table

To get the schema name for your Dataverse for Teams table, follow these steps:

  1. When you create your Dataverse for Teams tables and columns, each component is given a technical or schema name behind the scenes. You'll need to find that technical or schema name to use it in your flow. Return to Microsoft Power Apps by using the icon on the Teams left navigation bar. Select the Build tab and then select the team that you've been working in. Select the Asset table in the list of created items.

    Screenshot highlighting the Build tab and Asset table.

  2. Select Columns.

    Screenshot showing the Columns option selected.

  3. A behind-the-scenes view of your table and columns will show. Beneath the Name header are schema names, shown in a format like crao5_AssetId. Your schema names might differ; you'll have your own unique prefix that isn't similar to this example.

    Screenshot highlighting the schema names in the Columns section.

  4. Note your schema names for the following columns; you'll need them in this task and in subsequent tasks.

    Asset

    Asset Name

    Screenshot highlighting the schema names of Asset and Asset Name for the column.

  5. Return to Power Virtual Agents by using the icon on the Teams left navigation bar. Select the Chatbots tab and then select the chatbot that you've been working on to open it.

    Screenshot highlighting the Chatbots tab and the Office Helper chatbot selected.

Task: Create a new topic

To create a new topic, follow these steps:

  1. Go to Topics and then select + New topic.

    Screenshot highlighting the New topic button.

  2. Add the following trigger phrases and then select the button after each until all appear in the list:

    Want to order swag

    I need to make a request for merch

    Can I put in a request?

    Place an order for swag

    How do I put in an order?

  3. Select Details and then enter Request swag in the Name box. Close the Details pane.

    Screenshot highlighting the Details pane, showing Request swag entered in the Name box.

  4. In the Message box, add the following text:

    I can help you request Contoso Coffee swag.

    Screenshot showing text being entered in the Message box.

  5. Save your bot before continuing to the next task by selecting the Save icon in the upper-right corner.

Task: Create a flow to get a row from a Dataverse for Teams table

Power Virtual Agents in Teams comes with a built-in experience for Microsoft Power Automate, with templates to help make it easier for you to get your chatbot to call an action. In this task, you'll use Power Automate to look up the first item in your Assets table in Dataverse for Teams and then return that item as a suggestion for the user to request that item.

  1. Add a node and select Call an action. Select Create a flow, which will launch Power Automate inside Microsoft Teams.

    Screenshot highlighting the Create a flow option.

  2. Select Power Virtual Agents Flow Template. This template is designed to pass inputs from the chat to a flow and then provide outputs from the flow back to Power Virtual Agents.

    Screenshot highlighting Power Virtual Agents Flow Template.

  3. A screen might appear to confirm your flow connections. Select Continue.

  4. The flow template should display, with the Power Virtual Agents input and output steps. You're not bringing inputs from the chat into this flow, so you don’t need to do anything in that first stage. Select Add an action between the input and output steps.

    Screenshot highlighting the Add an action button.

  5. Search for list rows and then select the List rows Microsoft Dataverse action.

    This connector allows your chatbot to connect to your Dataverse for Teams tables, with various actions including creating, updating, deleting, or retrieving records.

    Screenshot highlighting the List rows action.

  6. Select the Assets table name from the dropdown list. You can type the word Assets into the box to make it easier to find your table.

  7. Select Show advanced options to view the rest of this action step.

    Screenshot highlighting the Show advanced options dropdown menu in the List rows action step.

  8. To retrieve the first row from the table, enter the number 1 in the Row count box.

    Screenshot highlighting the number one being entered in the Row count box.

  9. Compose a variable to store the information from the item that you retrieved in the previous step so that it's easier to pass it back to the chatbot. Add an action underneath this one, search for compose, and then select the Compose (Data Operation) action.

    Screenshot highlighting the Compose Data Operation action.

  10. In the action step, select the Inputs box, and then select the Expression tab in the Dynamic content box that appears. Enter the following expression into the function box of the Expression area of Dynamic content and then select OK. This expression gets the value of the item:

    first(body('List_rows')?['value'])

    Screenshot highlighting the Inputs box and the Expression tab to add an expression.

    A formula will show in the Inputs box.

    Screenshot highlighting the formula in the Inputs box.

  11. Return the asset name and ID to the chatbot. Select the Return value(s) to Power Virtual Agents step and then select + Add an output.

    Screenshot highlighting the Add an output button.

  12. Select Text and then enter the title as Name. In the Enter a value to respond box, go to the Expression tab on the Dynamic content box and then enter the following formula. Substitute the schema name for your own schema name (the word Name, as shown in the following screenshot) for the Asset Name column in your table that you noted previously. Your schema name will have a different prefix. Select OK.

    outputs('Compose')?['cra05_Name']

    Screenshot highlighting the Enter a value to respond box, showing a formula entered in the Expression tab.

  13. Repeat the previous step to add the ID to the outputs. Select + Add an output > Text. Enter the title as ID. In the Enter a value to respond box, go to the Expression tab on the Dynamic content box and then enter the following formula. Substitute the highlighted schema name for your own schema name for the Asset column in your table that you noted previously. Your schema name will have a different prefix. Select OK.

    outputs('Compose')?['cra05_AssetId']

Formulas will show in both output boxes.

> [!div class="mx-imgBorder"]
> [![Screenshot highlighting the Return Values to Power Virtual Agents action, showing formulas in both output boxes.](../media/compose-return-value.png)](../media/compose-return-value.png#lightbox)
  1. Change the name of your flow in the upper-left corner of the screen to Get first asset. Save by selecting the Save button.

    Screenshot highlighting the Get first asset flow and the Save button.

  2. After your flow has been saved, select the blue arrow next to the name of your flow to return to Power Virtual Agents. In the next task, you'll connect this flow to your chatbot.

    Screenshot highlighting the blue arrow to return to Power Virtual Agents.

Task: Connect your flow with outputs to your chatbot

Your next task is to connect your flow with outputs to your chatbot. Under your Message node, select Call an action and then select the flow that you created in the previous task. Make sure that you select the name of the flow, not the blue hyperlink, to show flow details (the link will take you back to editing the flow).

Screenshot highlighting the Get first asset option under Call an action.

Your flow is now connected to your chatbot.

Screenshot highlighting the flow details and the Power Automate outputs.

Task: Create a flow to submit a request for an asset

Follow these steps to create a flow to submit a request for an asset:

  1. Add a new Message node underneath the flow action node and then enter the following text:

    The first thing we always provide for new employees is:

  2. Select the variable button and then select the Name variable. This selection brings in the name of the first item from your Assets table that the flow retrieved in the previous step.

    Screenshot highlighting the Variable button and selecting the Name variable.

  3. Add a node for Ask a question. Enter the following text into the Ask a question box:

    Would you like me to request this for you?

  4. In the Identify box, open the options and then select Boolean.

    Screenshot highlighting the Identify box and showing the Boolean option.

  5. Edit the name of the variable to FirstRequest. Close the Variable properties pane by selecting the X in the upper-right corner.

    Screenshot showing the name of the variable changed to First Request.

  6. Add a new node and then select Add a Condition. In the left branch of the condition, select the FirstRequest variable from the dropdown list and then select True from the second dropdown list.

    Screenshot highlighting the Add a condition action, showing First Request and True selected in the dropdown lists.

  7. Add another node underneath and select Ask a question. Enter the following text:

    Please add your comments to submit with this request

  8. From the Identify option, select User’s entire response.

    Screenshot highlighting the Identify option and the User's entire response option selected.

  9. Change the name of the variable to Comments and then close the Variable properties pane.

    Screenshot showing the variable name changed to Comments.

  10. Save your bot by selecting the Save button in the upper-right corner.

  11. Create another flow, this time to request the asset on behalf of the user. Add a new node, select Call an action, and then select Create a flow.

    Screenshot showing the Call an action and the Create a flow options selected.

  12. Select Power Virtual Agents Flow Template.

    Screenshot showing Power Virtual Agents Flow Template selected.

  13. In the previous flow, you got the ID of the asset that the person is now requesting. You need to pass that ID into this flow as an input from the chatbot. Open the first Power Virtual Agents step in the flow by selecting it and then select + Add an input.

    Screenshot showing the Add an input option selected in Power Virtual Agents.

  14. Select Text, and then in the Input name box, enter AssetID.

    Screenshot highlighting the selection of Text and Asset ID entered in the Input name box.

  15. Repeat this step to add another input for the comments that are provided by the user. Select + Add an input, select Text, and in the Input name box, enter Comments.

    Screenshot showing the addition of another input name.

  16. Add an action under this input step.

  17. Search for add a new row and then select the Add a new row Microsoft Dataverse action.

    Screenshot of the Add a new row Microsoft Dataverse action being selected.

  18. This flow will submit a request for the user. Select Requests from the Table name dropdown list and then select Show advanced options.

    Screenshot showing Requests selected from the Table name dropdown list and the Show advanced options selection.

  19. In the Name box, enter New employee swag request. Select in the Comment box and then select Comments from the Dynamic content pane.

    Screenshot showing New employee swag request entered in the Name box.

  20. Select in the Asset (Assets) box and then enter the following expression (replace the prefix with the same prefix that you found in your own schema names previously). When you create the request and fill in the asset, you're connecting to the Assets table as well with the lookup column. The flow needs you to define the name of that connected table when you're creating this record.

    cra05_assets()

    Screenshot highlighting the Asset Assets row, showing the expression entered in the box.

  21. Select between the brackets in this formula and then select AssetID from the Dynamic content box. Make sure that AssetID dynamic content is between the brackets in your expression.

    Screenshot highlighting Asset ID in the expression.

  22. Change the name of your flow to Create a request. Save your flow and then use the back arrow next to the flow name to return to Power Virtual Agents.

    Screenshot showing the name of the flow changed to Create a request and the Save button.

Task: Connect your flow with inputs to your chatbot

To connect your flow with inputs to your chatbot, follow these steps:

  1. Scroll down to the question where you asked the user to add comments. Add a new node, select Call an action, and then select the flow that you created. You may need to select Overview from the left navigation to get to this screen.

    Screenshot showing Call an action and Create a request selected.

  2. Map the variables that you created in Power Virtual Agents to the inputs from the flow. Select your variables from the dropdown lists as follows:

    AssetID (text) gets value from - ID

    Comments (text) get value from - Comments

    Screenshot showing the variables selected from the dropdown lists.

  3. Add a confirmation message so that the user will know that their request has been sent. Add a node underneath and then select Show a message. Enter the following text in the Message box.

    Thank you, your request for has been submitted.

  4. Select after the word for and then select the Name variable.

    Screenshot highlighting the Name variable.

  5. Add another node underneath to end the conversation with a survey.

    Screenshot showing the addition of another node and the End the Conversation node.

  6. Scroll up to the Would you like me to request this for you question node. Under the condition branch for All other conditions, add an End with survey node.

    Screenshot highlighting the End of Conversation node.

  7. Save your bot by selecting the Save icon.

Task: Test your bot

Now it's time to test your bot.

  1. Turn on the Track between topics toggle at the top of the Test bot pane. Type a trigger phrase, such as I want to order swag, in the Test bot pane. The bot should return a suggested item, which is the first item in your Assets table.

    Screenshot showing the Track between topics toggle switch turned on in the Test bot pane.

  2. Continue the conversation with the chatbot by selecting Yes and then entering your comments:

    Can I get this delivered to me by Monday, please.

  3. A confirmation message will appear, showing the name of the asset and the End of Conversation topic.

    Screenshot highlighting the conversation message with the name of the asset.

  4. To check that the request has been submitted, select the Teams icon in the left navigation bar. Go to the team and channel where you created your app in a previous lab in this learning path. The request that you submitted should show in the app.

    Screenshot highlighting the submitted app in Teams and in the channel.

Congratulations, you've built a bot that can answer questions, retrieve an asset from your Dataverse for Teams database, and submit a request on behalf of the user.

In the next exercise, we'll publish and share it and use it in Teams chat.