Return a list of results
It's common to ask an agent to look for data in an external system and return a list of results. To do that, an agent can call a Power Automate flow to:
- Authenticate and connect to an external solution.
- Run a query based on the user input.
- Format the results.
- Return the results to the agent.
This example uses the Dataverse connector in Power Automate to search for accounts. The connector returns a list of results that includes the account name, city, and account number to your agent.
Prerequisites
- Understand how to create a flow from the Copilot Studio authoring canvas
- Use input and output variables to pass information
- Configure Dataverse search for your environment
Set up a Dataverse Account table
The Account table is a standard table available by default in Power Platform environments. However, it doesn't come with account data. Before your agent can search for accounts, you must populate the Account table.
If you already have an Account table with data, skip this step and move on to Create a topic. However, remember to use search terms relevant to your data when you test your agent in later steps.
Go to the Power Apps portal.
In the navigation pane, select Tables.
Select the Account table, and then on the table properties page, select Edit.
Add the following rows to the table:
Address 1: City Account Name Account Number Seattle Contoso Inc AC0125 San Francisco Contoso Residences AC0255 Olympia Contoso Meal Delivery AC0035
Create a topic
In Copilot Studio, go to the Topics page for your agent.
Create a topic called Account search.
Add the following trigger phrases:
- I'm looking for a customer
- I'm looking for an account
- search account
- search customer
Add a Message node and enter the message "Sounds like you're looking for an account. I can look that up for you."
Add a Question node and enter the message "What's the name of the customer you're looking for?"
For Identify, select Organization.
User's entire response would also work. However, by selecting the Organization entity, you take advantage of the agent's language understanding capabilities to extract the organization name from the response.
For Save user response as, rename the variable to "organization".
Create a flow
Select the Add node icon
below any node, and select Add an action.
On the Basic actions tab, select New Power Automate flow.
In Power Automate, select the name of the flow and replace it with Search account.
Select the Run a flow from Copilot flow trigger and add a Text input parameter named Organization.
Select the Add icon below the Run a flow from Copilot flow trigger.
In Add an action, search for "Microsoft Dataverse", and select the Search rows action.
This action uses fuzzy matching to find relevant accounts in your Dataverse Account table.
In the Search term box, enter a slash (
/
), select Insert dynamic content, and then select your Organization input parameter.For Advanced parameters, select Show all and set the following values:
- Table filter Item:
account
- Sort by Item - 1:
search.score desc
- Sort by Item - 2:
name asc
- Table filter Item:
Format results
The Search rows action returns the List of rows variable, which contains JSON data. Before you can use the data, you must analyze it with the Parse JSON action.
Select the Add icon below the Search rows action.
In Add an action, search for "Data Operation", and select the Parse JSON action.
In the Content box, enter a slash (
/
), select Insert dynamic content, and then select List of rows.Copy the following JSON schema and paste it in the Schema box:
{ "type": "array", "items": { "type": "object", "properties": { "@@search.score": { "type": "number" }, "name": { "type": "string" }, "address1_city": { "type": "string" }, "accountnumber": { "type": "string" } }, "required": [ "name" ] } }
Select the Add icon below the Parse JSON action.
In Add an action, search for "Variable", and select the Initialize variable action.
In the Name box, enter "ListOfAccounts".
For Type, select String.
Select the Add icon below the Initialize variable action.
In Add an action, search for "Control", and select the Apply to each action.
In the Select an output from previous steps box, enter a slash (
/
), select Insert dynamic content, and then select the Body variable under Parse JSON.Select the Add icon inside the Apply to each action.
In Add an action, search for "Variable", and select the Append to string variable action.
For Name, select ListOfAccounts.
Copy the following text and paste it in the Value box:
- @{items('Apply_to_each')['accountnumber']}: @{items('Apply_to_each')['name']} - @{items('Apply_to_each')['address1_city']}
Add a line break after the snippet to make each result appear on its own line.
In the Respond to Copilot action, add a Text output.
For Name, enter "FoundAccounts".
For the value, enter a slash (
/
) in the box, select Insert dynamic content, and then select the ListOfAccounts variable.Save and publish your flow.
Call the flow from Copilot Studio
In Copilot Studio, select the Add node icon
under the Question node, select Add an action, and then select the flow you created earlier, Search account.
Set the flow input parameter to the output variable from the Question node: Organization (String) gets its value from the organization variable.
Add a Message node and enter the message "Okay, this is what I found."
Add a second Message node. Select the Insert variable icon, and then select FoundAccounts.
Select Save.
Test your agent.