Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Learn with Subs / Using Adaptive cards to acc...

Using Adaptive cards to accept user Inputs, validation to interact with D365F&O

Subhad365 Profile Picture Subhad365 19 User Group Leader

Adaptive Cards 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 capability for your agent, you can include text, graphics, and buttons, as a JSON representation. Few days back I was showing on another blog, how to fetch data from D365F&O into Adapatve Cards, in Copilot Studio (https://community.dynamics.com/blogs/post/?postid=68c86dc3-31fc-ef11-bae3-7c1e525b5e9d).

In today’s discussion, I would like to show how could you input instructions into Adaptive cards, to make them flow into D365F&O and perform validations to them.

What am I trying to do

I am asking Copilot studio to update the name of a released product:

To which the Copilot responds like this:

Here I can put in the necessary Item code, the desired item name and the company in which I want to do so. And the Copilot will return me:

And if you try to Submit the form without filling up the information, it would error out as:

Interesting?
Let us see, how all these could be done.

Designing a form that can accept inputs

Step 1

Let us start our topic by defining it as follows:

To which the I am adding a node: to send a message –

This will essentially add a message node like this:

Click on Add >> Adaptive card:

This introduces the Adaptive Card:

Click on the card >> Click on the Adaptive Card designer:

This will open the URL: https://adaptivecards.io/designer/  >> select New Card

And you can choose from a number of options: what is that you exactly want to create. I choose the following form type to accept user inputs:

This contains enough of design inputs to do whatever I am looking to implement (i.e. taking the Item code, item name and data area id details and doing the validations). Click on ‘Copy card payload’:

And paste it in the card design in Copilot Studio.

Step 2

Now let us change the design of the card. So firstly we need three inputs from the user:
  1. The item number
  2. The desired new name of the item
  3. And the legal entity to which this released product belongs.
Copy the payload which you copied from the above step and then change the view from JSON to Formula mode:

Now, paste the below payload into your formula designer:
{
  type: "AdaptiveCard",
  '$schema': "http://adaptivecards.io/schemas/adaptive-card.json",
  version: "1.5",
  body: [
    {
      type: "TextBlock",
      text: "Product update form",
      size: "Large",
      wrap: true,
      weight: "Bolder",
      style: "heading"
    },
    {
      type: "Input.Text",
      id: "ItemId",
      label: "Item code",
      isRequired: true,
      errorMessage: "This is a required input",
      placeholder: "Please enter product number"
    },    
    {
      type: "Input.Text",
      id: "NewItemName",
      label: "Item name",
      isRequired: true,
      errorMessage: "This is a required input",
      placeholder: "Please enter product name"
    },
    {
      type: "Input.Text",
      id: "Company",
      label: "Company",
      isRequired: true,
      errorMessage: "This is a required input",
      placeholder: "Please enter legal entity"
    }

  ],
  actions: [
    {
      type: "Action.Submit",
      title: "Submit",
      style: "destructive"
    }
  ]
}

Explanation:

  1. The display labels contain the name of the controls. Change them as per your  requirement.
  2. Error message: makes the control as a mandatory control. You can change your message as needed.
  3. Button Action.Submit makes the button as a Submitting button and posts back your request for further execution. Additionally I kept the Style as ‘destructive’ so as to make it Red in color.
  4. Whatever IDs you are defining in your card, they all would be available as an inputtable/capturable control in your card.
Go all the way down to Edit Schema to see what are the outputs that you can get from the card:

This will show you the variables you are getting from the card:

You can change the variables you find the variables if not correct.
This will make the card control looks like this, with all the variables:

Step 3

Next I am going to call a flow that updates the name of the released product:

Note that how am I passing on the controls/variables obtained from the above step into the Flow. The flow is pretty simple that accepts the input from the caller:

And then I am obtaining an AADToken:

And then I am calling the OData entity endpoint to update the released product name:

I am performing a Patch operation on the Odata entity shown above:
<<Base_UrL>>/data/ReleasedProductsV2(ItemNumber= '<ITEMID>',dataAreaId= '<DATAAREAID>')?cross-company=true
This will update the released product with the necessary search name I am getting from the user.
And finally I am sending back the status of the result (success/failure):

This I am sending back from my flow to Copilot as a message and displaying to the user:

Which gives me after the update:

Using Adaptive Input Cards, you can extend this to any type of CRUD operation: letting the user choose from Dropdowns and texts, ex:
  1. Choosing the item from a dropdown
  2. Choosing the legal entiy from dropdown
  3. Using check mark controls as NoYesId
And then posting the information back to D365F&O and getting back the responses.
With that let me conclude the discussion here. Please try the same and let me know how it went. Much love and namaste 😊
 

Comments

*This post is locked for comments