Create Dataverse rows containing LOOKUP fields with Copilot Studio

As we’re improving our processes using Copilot Studio and Generative AI, we need to make sure our agents are proficient and know exactly what to do. In today’s post, we’re going to see how our Copilot agent can successfully create rows in Dataverse where lookups fields are present.

Backend

Of course, you guessed our backend data source was Microsoft Dataverse. We’re going to work with the following tables:

  • Product
  • Order

The Product table contains the following columns:

  • Name (primary)
  • Description (multiline of text)

The Order table contains the following columns:

  • ProdOrderID (autonumber – OPTIONAL)
  • Product Name (lookup to the “Name” in Product table)

Scenario

In our scenario, we’d like the agent give us some details about the products, and create new orders in the Order table with the lookup fields.

We’ll be using Generative answers, the Dataverse connector, and give specific instructions to our agent 🙂

Copilot Studio Agent

Knowledge

Start by creating an agent from Copilot Studio and make sure that generative orchestration is enabled.

Next, we’ll add our 2x Dataverse tables as Knowledge sources.

  • Click on Add Knowledge
  • Select the Dataverse tile
  • Select the Product table
  • Click on Add to agent

Repeat for the Order table, and if needed, go back into each to add a proper description. While it’s possible to add them at the same time, it’s better to have them separate.

⚠️ It make take a few minutes for the agent to get results from the knowledge sources if you have a small set of data, to potentially a few hours for larger sets.

Instructions

Let’s add (some of) the most important bit: Instructions.

SPOILER: We’re not going to add the full instructions now! Let’s see first how the agent behaves and if we get some results, so we can fine-tune later on.

  • Navigate to Instructions (overview page)
  • Click on Edit
  • Enter your instructions
  • Click on Save

Let’s test the agent 🙂

Tools

To be able to do something other than fetching data, we’re going to add tools. While we could use the Dataverse MCP Server, today’s about individual Dataverse connectors 🙂

From the Overview page, click on + Add tool, or navigate to the Tools tab to add a tool, and click on the Microsoft Dataverse connector tile.

Make a connection and click on Add and configure.

Let’s configure the tool. The Inputs section is going to be important for the agent to action the users’ queries.

We don’t want the Environment and the Table name to dynamically filled with AI, so click on the dropdown and select Custom value. Then proceed to enter your own values and click Save.

If you have any other required values in your table, they’ll show below as well.

Let’s add more instructions for our agent to be aware of the tool to use when adding an order:

When users want to add an order, use the "Add new row to the Order table" tool to create a new record in the "Orders" table.

As you can see below, the agent used the correct tool, but in the Order table, the Product Name is a lookup field. Therefore, it’s having trouble patching a String!

connectorRequestFailureThe connector ‘Microsoft Dataverse’ returned an HTTP error with code 400. Inner Error: URL was not parsed due to an ODataUnrecognizedPathException. Resource not found for the segment ‘Microsoft Surface Laptop’ provided in the URL.

⚠️ The format expected for a lookup value is @odata.bind

List Rows with Dataverse connector

Before creating a new row, we’ll get the correct values directly from Dataverse using List Rows.

Let’s add another Tool >> Dataverse connector >> List rows from selected environment, and modify our instructions for the agent to use this tool.

When we test our agent, our order is placed 🙂

Hope it helps – Thanks for reading! 🙂

Leave a Reply

Discover more from Veronique's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading