/ / Add a Button to a Teams List to Trigger a Flow

Add a Button to a Teams List to Trigger a Flow

Let’s say you’ve created a list either directly in SharePoint or within the Teams lists app. If you regularly need to take an action based on a list item, it’s nice to have a button built into the list that will automate the process for you. Luckily, this only takes a few steps:

Create a instant flow for a selected item

In Power Automate, create a new instant cloud flow, and select the “For a selected item” trigger.

New instant cloud flow for a selected item

Select the list that will eventually hold the button.

Selecting the list for the trigger

After you’ve selected the item, you’ll need to access all content and data contained within it. The initial trigger doesn’t include this information, so you need to add a “get item” step. Feed it the ID from the “For a selected item” step.

Getting more information about the list item

Add the action you want the button to initiate

At this point, you can do almost anything you want with the list item, including triggering an adaptive card, sending an email, changing data in the list, or anything else within Power Automate’s capabilities. For this example, I’m going to just compose a simple status message that the Flow bot will post in the Teams channel.

First, I’ll use a “Compose” step to put together a message that formats the message for the Flow bot. You don’t necessarily have to do this (you could just write the message within the “Post a message” step), but it does become easier to manage if you’re composing a more complex message.

Second, I’ll create a “Post a message as the Flow bot to a channel” and use the “Outputs” of the Compose step for the message content. The headline is optional, but you can use dynamic content from any of the previous steps to populate it.

Sending a message in Teams based on the list item

Collect and record the flow ID

While you’re in the edit view of your flow in Power Automate, take a look at the URL. It should be something like https://us.flow.microsoft.com/manage/environments/Default-f2999992-cb82-4b99-a35f-c280c72f9999/flows/29e9999-2015-9999-9999-988dfdd22931 and the last underlined section is your flow ID. You’ll need that later, so copy or save that string of characters.

Create a column to hold the button

Now within your list, you’ll need to create a new column that will hold the button for each list item. The easiest way to set it up is as a single line of text with all the default settings.

Column that will contain a button for my Orders list

I’d recommend moving that column to be one of the first in your list, so that it’ll show up without having to scroll to the right at all.

Column visible without scrolling

Modify advanced formatting

Now you have to create some advanced JSON formatting to create a visual button and connect the button to your flow from Power Automate. Go to your column settings and select “Format this column” from the menu.

Format the column for the button

Switch to the advanced view using the link at the very bottom of the “Format Button column” window, shown below:

Enter advanced mode to edit the button formatting

In the text area that appears, enter the following JSON. Replace the underlined flow ID with the ID you recorded from the edit view previously. Be sure not to accidentally delete the slash at the end, since that’s part of the JSON formatting.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "children": [
    {
      "elmType": "button",
      "style": {
      },
      "txtContent": "Post status",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"29e9999-2015-9999-9999-988dfdd22931\"}"
      }
    }
  ]
}

Using this formatting, you’ll now have a functional button that appears for each item in the column you’ve designated. This will include the default button formatting. If you’d like to change the button formatting (background, border, text color, etc.) you can reference Microsoft’s official documentation on button element syntax.

Pretty buttons in the Button column!

Try out the button and flow

The first time you click the button, the flow will double-check that the permissions are correct and allowed. Once you’ve reviewed everything, click continue and run the flow.

Review permissions the first time you run the flow

When running the flow as described/built in this post, we get a successful message from the Flow bot letting us know the status of the list item!

Automated message produced by clicking a button that initiates the flow

Next steps might include creating a deep link back to the list item within the message, setting up a flow that sends an email using list data, or creating a button that’s only available when the list item meets certain criteria.

Similar Posts

Leave a Reply

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