Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Learn with Subs / Implementing Lookups in Ada...

Implementing Lookups in Adaptive Card in Copilot Studio for D365F&O

Subhad365 Profile Picture Subhad365 19 User Group Leader
Amigos, Adaptive Cards are amazing. They enable you to add snippets of content to Copilot Studio agents that can also be openly exchanged with other cloud apps and services. To provide rich conversation UI based capability for your agent, you can include text, graphics, and buttons, as a JSON representation. And because they're platform-agnostic, you can easily tailor Adaptive Cards to your needs.
You can design Adaptive Cards using the Adaptive Cards Designer or author directly using JSON code. The Adaptive Card node allows you to send an Adaptive Card containing one or more submit buttons, and optionally, one or more form input fields. Copilot Studio then stores user responses in variables for use later in the conversation.
This article can give you a cool hack to implement lookups on a control in Adaptive Cards in Copilot Studio for D365F&O.

What I am trying to do

I am asking my copilot studio to allow me to change a product name:

And the copilot comes up with following prompt:

Clicking on the product drop down, it gives the following lookup:

Interesting? Wondering how can you do this? Read along 😊

Step 1

Lets begin by defining your topic phrases:

Here we are telling the copilot studio about the list of triggering phases to call the topic.
And then in the next step I am calling a Flow (PowerAutomate) that can get me the list of the available products:

For our ease of use, I am passing on the Legal Entity as “USMF” which in turn is passed on to the Flow like this:

In the above sequence I am passing on the Legal entity value that I am getting from Copilot and calling the Token generation logic by calling the https://login.microsoftonline.com:

With the standard setup of: tenant_ID, Client_Id, secret and base URL. The token which I am receiving from the above step is what we are sending in the next step to call the list of products from D365F&O:

Where we are just selecting the ItemNumber from the list and filtering on the basis of legal entity, with cross-company as true.
Here is now we need pass on the list of Items which we are getting from the endpoint call, by parsing the JSON response.
Alternately (what I have done) we can pass this payload response as an input to an AI prompt that can convert the JSON response as a string output:

The above is an input payload that the prompt can understand and convert that as comma separated string.
In the last step I am just returning this response back to Copilot studio:

Step 2

The above step would give me a comma separated string: ItemI1, Item2,Item3,Item4. To use this as a data source, we need to convert the same as a Table:
ItemId
Item1
Item2
Item3
Item4

Hence we are using a local variable called ItemNumberArray (which is a table type variable) and we are doing the conversion by using the Spilt function:

Step 3

Here we are now going to introduce the adaptive card by simply selecting the option from the response:

Which would give you the adaptive card, that you can alter by using Input.ChoiceSet type of control to make it look like a lookup control:
{
      type: "Input.ChoiceSet",
      id: "ItemId",
      style: "compact",
      label: "Select product",
      isMultiSelect: false,            
      choices: ForAll(Topic.ItemNumberArray,        
      {
        title:  Value,
        value: Value
      })
    }

Let me explain the trick here 😊
When you use a Input.ChoiceSet and you use Style = compact, it’s essentially you are asking it to use as a drop down/combobox. Label = the label of the control and IsMultiselect = false, means I am not allowing the Copilot to select multiple values.
In the Choices: you have specify the elements that you want to populate your control . Hence I am using the ForAll function from PowerFx, which lets you to use the table variable and looping through its elements and assign it to the title and value of the combobox:


Now let me pause here, regarding how to update an existing records using Copilot, I have already covered in my previous post: https://community.dynamics.com/blogs/post/?postid=075a4b08-e500-f011-bae3-6045bdd5da15

Testing it

Let us now test the copilot:

I am selecting the above item and giving a new description to it. On pressing Submit I am getting:

Question

Why did I call the Flow to get the item list at the start of Topic? Shouldn’t it have been on the Lookup event of the “Select product” control?
The answer is: as all calls to Flows are kept synchronous, hence we are keeping this call as once, at the start of the Topic. If you are to call the flow every time you are looking up on the control, then it will bring immense performance issues. Hence we are spooling all the items’ list at the start of the topic and using that list down the line.

   



 

Comments

*This post is locked for comments