Triggering an Adaptive Card in Teams
/ / Triggering an Adaptive Card with a New List Item

Triggering an Adaptive Card with a New List Item

When a new item is created in our Teams List app orders list, it’s important that everyone in the channel is aware. Additionally, we need to manually update the status of each order. This post describes how to use Power Automate to trigger an adaptive card in Microsoft Teams as a notification that subsequently updates a new list item. The steps to do so include:

Create a flow triggered by list item creation

Create a new automated cloud flow that’s triggered when an item is created.

Trigger when a new item is created

Send a notification message to the channel

To test whether the trigger works properly with teams, let’s just send an initial message that doesn’t include an adaptive card. First, set the correct list for the trigger.

Fill in list details

Next, add an operation to “Post a message”

Create a new action to post a message

Fill out the details of this step so that your message goes to the correct Teams channel. You can use the “Add dynamic content” button to pull up data from previous steps. In the image below, I’ve used fields from the list to populate the message that will be displayed in Teams.

Compose the message using Dynamic content

Save, run a manual test, and create a new list item to watch your flow in action.

Automated message posted to the channel

Teams messages use HTML for the message body, so you can get fancy with the message formatting if you want:

Fancy automated message posted to the channel

Design an adaptive card to request the status

Now let’s say you have a “status” choice column in your list that needs to be manually updated every time a new order comes in. You can use an adaptive card to ask about this!

Add status column

Add a step in your flow to “Post adaptive card to a Teams channel and wait for a response” then fill it out with the appropriate channel information. I recommend renaming the step to something shorter and recognizable, because you’ll need to reference it later.

Create a new action to post an adaptive card
Fill out the channel information

Fill in the Message block with the JSON for the adaptive card. If you’re not familiar with building an adaptive card, check out https://adaptivecards.io/designer/ to build based on templates. Here’s the JSON used in this example, which allows the user to choose between the four choices I created for statuses in the list:

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.2",
    "body": [
        {
            "type": "TextBlock",
            "text": "Assign a status to order @{triggerOutputs()?['body/Title']}",
            "wrap": true
        },
        {
            "type": "Input.ChoiceSet",
            "choices": [
                {
                    "title": "Order inventory",
                    "value": "Order inventory"
                },
                {
                    "title": "Process",
                    "value": "Process"
                },
                {
                    "title": "Ship",
                    "value": "Ship"
                },
                {
                    "title": "Need more info",
                    "value": "Need more info"
                }
            ],
            "placeholder": "Select a status",
            "id": "choiceStatus"
        },
        {
            "type": "ActionSet",
            "actions": [
                {
                    "type": "Action.Submit",
                    "title": "Submit"
                }
            ]
        }
    ]
}

The adaptive card ends up looking like this:

Selecting status from a drop-down menu on an adaptive card

When the user submits a response, it can be referenced using the format outputs('Status_Adaptive_Card').body.data.choiceStatus which allows us to use the data to…

Update the status for the list item

Create a new “Update item” step in the flow. Select the correct site and list, and feed it the Id from your initial “When an item is created” trigger. In the field you want to update, add dynamic content and create an expression using the output from the previous step.

Update the list item

You can leave any non-required fields blank.

Update the list item status

Success! Now what…

Test the flow, and after you submit a status, check your list item. It should be updated with the new status!

Item status has been updated based on input from adaptive card!

This concept will apply to just about any field you’d like to update when a new list item gets added. To make this smoother, wouldn’t it be nice if the notifications used deep linking to give you access directly to the list item? Also, it’d be handy to have threaded conversations about the list item so your team can easily access prior discussions.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *