Button in SharePoint List to Trigger Power Automate

In SharePoint modern lists, conditional formatting can be done, and there is a great detailed reference by Microsoft.  I was trying to find a way to create a nice pretty button right there on a SharePoint list, to quickly click to run a workflow.  With that in place, end users won’t have to wonder which menu and where to click in order to get that item approved (or run any workflow at all).

Microsoft’s reference on how to do this is here.

After reading this and trying it myself, I made a couple of tweaks to it, that you may like.  In this post, I’ll explain how it works, and what I did.  Here are a couple of examples, one with a list (Customers), and one with a library (Policies):

sharepoint-conditional-formatting-policies

There are two ways I’ll demonstrate, one way is with a hyperlink, and the other with a button.  The Policy Owner column above is a hyperlink, and the Button column is a button.

Check out my Advanced Power Automate Course

First of all, you’ll need to decide which Flow you want to run, and get the GUID of it.  Here’s how to create a flow if you don’t already have one, using a specific template for manager approval.  The important thing is that its trigger is based on the selected item, NOT based on when an item is created or modified.

  1. Go to https://flow.microsoft.com
  2. In your list or library, click the Flow drop-down in the toolbar, and choose Create a Flow.
  3. Choose the Flow called “Request manager approval for a selected item”.
  4. On the next screen, click Continue.
  5. Now, in the flow design screen, click Save at the top right.
  6. Go back to your list of Flows, and then open this Flow.  For any flow in your list, here’s how to get the GUID, it’s in the URL.
  7. My URL looks like this https: //us.flow.microsoft.com/manage/environments/Default-9d3ccee1-5cf8-4e08-887c-53b2a210967b/flows/de138f88-1e85-5d0f-a3ad-fa9b0c9e5ac5/details.  I just need that part in red.  Copy just that part to your clipboard.  de138f88-1e85-5d0f-a3ad-fa9b0c9e5ac5
  8. You’ll also need to share this Flow so that other people can run it besides you.  Add users or AD groups as run-only users:

Next, I’ll show you how to create the column as a hyperlink.  It doesn’t matter what kind of column it is, or even if it has a value in it or not.

My policy owner’s name is in a people column called Policy_x0020_Owner

    1. Go to your list or library, click on the name of the column, and click Column settings, then choose Format this column.
      sharepoint-format-polcy-owner-column
    2. Your pane will show on the right side of the screen, to paste this code in.

{
“$schema”: “https: //developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json”,
“elmType”: “span”,
“style”: {
“color”: “#0078d7”
},
“children”: [
{
“elmType”: “span”,
“attributes”: {
“iconName”: “Flow
}
},
{
“elmType”: “button”,
“style”: {
“border”: “none”,
“background-color”: “transparent”,
“color”: “#0078d7”,
“cursor”: “pointer”
},
“txtContent”: {
“operator”: “+”,
“operands”: [
“[$Policy_x0020_Owner.title]”,
Approval
]
},
“customRowAction”: {
“action”: “executeFlow”,
“actionParams”: “{\”id\”: \”86dfdf10-8d99-4914-8e98-fe4b21ed7e34\”}”
}
}
]
}

garth-fort-approval

  1. I’ve color coded the parts that I changed, to explain what each one is.
    Red – My Flow GUID that I obtained in that first set of steps above
    Purple – the name of my column.  The only reason I had to put the .title in it, is because it’s a person column.  All column types don’t need this extra part.  Reference.
    Blue – the word that I’m showing after the person’s name
    Green – the name of the icon that I’m showing in front of the person’s name.  This one is called Flow, but there are bunch of others here.

Next, I’ll show you how to create the column as a button, shown above in my Button column, which is just a text column with nothing in it.  Do step one from above first, then in the column formatting box, use this code:

{

{
“elmType”: “button”,
“txtContent”: “Get Approved“,
“customRowAction”: {
“action”: “executeFlow”,
“actionParams”: “{\”id\”: \”f191e7c8-1a36-4553-9d64-607764fc6f83\”}”
}

}

get-approved-button

This one is much simpler.  I didn’t make the text dynamic at all, it just says Get Approved for all of them.  Clicking the button launches my Flow.

Red – my Flow GUID.

Blue – the words on the button

What if I want the button to be a different color?  Then, the code would look like this instead, with a purple button with white text:

{
“elmType”: “button”,
“txtContent”: “Get Approved”,
“customRowAction”: {
“action”: “executeFlow”,
“actionParams”: “{\”id\”: \”86dfdf10-8d99-4914-8e98-fe4b21ed7e34\”}”
},
“style”: {
“background-color”: “purple“,
“color”: “white”

}}

purple-approval-button

What if you only want the button to show under a certain condition.  In this example, I only want this button to be visible if the content approval status is “Pending”.  Here’s the code for that:

{
“elmType”: “button”,
“txtContent”: “Get Approved”,
“customRowAction”: {
“action”: “executeFlow”,
“actionParams”: “{\”id\”: \”86dfdf10-8d99-4914-8e98-fe4b21ed7e34\”}”
},
“style”: {
“background-color”: “purple”,
“color”: “white”,
“visibility”: {
“operator”: “?”,
“operands”: [
{
“operator”: “==”,
“operands”: [
“[$_ModerationStatus]”,
Pending
]
},
“visible”,
“hidden”
]
}
}
}

In the above code, here are the important parts:

Red – my column’s system name is _ModerationStatus

Blue – the value of the status is pending

In the syntax, a question mark (?) operator is used to create a condition, like an IF statement.  So, in the “visibility” section of the code above, we’re saying IF the ModerationStatus equals (==) Pending, then “visible”, otherwise (if it’s not pending), then “hidden”.

policies-approved-flow

Here’s my SharePoint Power Hour video where I demonstrated how to do all of this, along with how to do the workflow that works with the content approval status in the list/library.

2019-06-21_10-52-40.png

251 comments

  • Pingback: Personnaliser un flux d’approbation par Power Automate | KTNN SharePoint

  • can you execute a flow without the next step that always popup

    Like

  • Hey Laura-you’ve been so helpful over the years. The USMC is just now migrating from 13 to Online. Yeah I know…lol. I’ve been able to successfully automate a document set library with a 4 layer approval, however, I am trying to start it with a button – I want to insert the button on the document set welcome page. I have inserted it in the column like you did – thank you for that, but my flow just spins. Nothing seems to be wrong with it. I keep seeing that manual flows don’t work on document sets…but but but…this can’t be true…

    Like

    • Sorry I’ve never tried that on a document set, but it doesn’t surprise me that it doesn’t work, since a document set is really a folder, and folders can’t typically be triggers for flows.

      Like

  • Hey Laura,

    Loving some of the snippets you post up. Any chance you can extend this to include showing different buttons depending on status column… eg.
    if (approvalStatus) = ‘pending’ {
    buttontext = ‘submit for approval’
    elseif (approvalStatus = ‘approved’){
    buttontext = ‘set unapproved’
    }

    Can you do switches with formatting on columns? Do you have any good articles you’ve published about understanding the formatting options, or can link to any good resources?
    Thanks from Australia!

    Like

    • In the part of the post that starts with “What if you only want the button to show under a certain condition…” that’s where I show that syntax. I don’t know much more about JSON than that, though.

      Like

  • Hi Laura

    Even the button is there and ID of Flow is adapted no action on click. Also I cannot see my flow to be launched manually on the corresponding sharepoint list. Is there anything I need to do on the flow itself in order to publish it on a specific list?

    Like

    • In step 2 of the instructions in the blog post, it says to go to your list, and click “create a flow”. That’s how it knows which list.

      Like

    • found it out finally…..as my Environment for Flows (Dev) is not the same as for the Sharepoint as such I needed to add the full path from the flow reference as you get on Export -> Get Flow Identifier and not only the ID that way it worked 🙂

      Like

  • Hi Laura – great Site. Worked for me that way. Is there any way to Handover a specific Field value from the List Row as a parameter to the Flow Input Fields?

    Like

  • This is a very nice post. I have a question/concern. The button only launch the flow for the 1st time but if we cancel the launch and click on the button again nothing happens unless we refresh the page and click the button again. Is there any solution for it?

    Like

  • I noticed that the workflow’s trigger is “on a selected item/file”. is it possible to use the manual trigger instead so that I can use this workflow in other libraries?

    Like

  • Thanks WonderLaura. This is a great solution that I’ve used several times now so thanks for that. I have just found an issue which looks like a SharePoint bug or limitation perhaps and wondered if you had any knowledge of it. If I add the list into a Modern Page I can click on the button to launch the Flow but absolutely nothing happens. Any thoughts? What I really want to be able to do is offer the end user the ability to sit on their home page and launch the Flow so I thought having a dummy list to support this functionality would work well. If there’s another way you know of to allow a user to run a specific Flow from a Modern Page then I’m up for that!
    Thanks again, you’re one of my very few go tos

    Like

  • Hi, this code works for Azure Logic Apps? I’m looking to trigger an Logic App using a button in SharePoint Online.

    Like

  • Hi, do you know if it can be solved so it is possible to use this solution in a web part on a page? It is no longer possible to click on the buttons then

    Like

  • Hi Laura,

    I have been using similar JSON for a document approval workflow and haven’t made any changes to the JSON for the button column for months. Today the buttons for all the libraries where I have used the button, including different tenants, have stopped showing. The issue seems to be with the visibility section. If I change the section to “visibility”: “visible” and change nothing else in the JSON, all the buttons start showing (they show all the time, not just when the Approval Status is “Pending”). Does anyone else now have the same issue. It seems like a system wide issue as i have checked 5 different SharePoint Tenants and they all have the same issue.

    Like

    • Is no-one else having this issue? I thought someone would reply as it should affect everyone who used Laura’s approval button JSON above…..

      Like

    • I don’t know, Microsoft must have changed something in their code that determines whether something is visible or not.

      Like

    • Hi,
      I received an answer in another post I made in the Microsoft forums. It confirms there was a change in how the Approval status is handled with JSON. I am not super skilled in JSON so I don’t know what it means. Can anyone here help with what changes are needed to the below code?

      “visibility”: {
      “operator”: “?”,
      “operands”: [
      {
      “operator”: “==”,
      “operands”: [
      “[$_ModerationStatus]”,
      “Pending”
      ]
      },
      “visible”,
      “hidden”
      ]
      }

      Answer from the forum: This is happening because of recent change in JSON schema to officially support Approval Status column in JSON formatting.

      Due to this update, the @currentField and [$_ModerationStatus] will resolve to internal code (enum value) and @currentField.displayValue and [$_ModerationStatus.displayValue] will resolve to the localized string (I guess according to language).

      Post link:
      https://techcommunity.microsoft.com/t5/sharepoint/json-format-broken/m-p/2968990/highlight/false#M55139

      Like

    • Here is a post from GitHub detailing how this happened. Microsoft added a new feature which broke JSON formatting for the Approval Status filed…. thanks MS!

      https://github.com/SharePoint/sp-dev-docs/issues/7513

      Like

    • Hi All,

      with the help of some nice people from the Microsoft SharePoint forum (@ganeshsanap & @Danie365), I have a fix that I have tested and is working for me. Please test yourselves.

      Replace:
      “visibility”: {
      “operator”: “?”,
      “operands”: [
      {
      “operator”: “==”,
      “operands”: [
      “[$_ModerationStatus]”,
      “Pending”
      ]
      },
      “visible”,
      “hidden”
      ]
      }

      With this:
      “visibility”: “=if([$_ModerationStatus.displayValue] == ‘Pending’, ‘visible’, ‘hidden’)”

      Liked by 1 person

  • Hi WonderLaura, this is immensely helpful!
    Is it possible to amend the button to open the Edit form for that item? That would save my users a lot of pain…
    Thanks
    Nick

    Like

    • To create a button to edit an item, you would use a hyperlink action instead of a flow action, and the path is the list URL with editform.aspx?ID=
      and then after the =, that’s where you would need it to have the ID of that list item. I’ve never done it, but that seems like it would be the way.

      Like

  • Laura, Great site! Is it possible to have a column value trigger a value inside of another column in the Same Lists page. Ex; choosing a value of -“Patient Ready” in column 1 , trigger a value of a “Time stamp” in column 2. thanks

    Like

  • Thank you so much for the tutorials. I noticed that if you enable the Document ID Service Site collection feature, you can fetch the listItemId guid always in the itemurl. So this works for all views and all doc libraries

    Liked by 1 person

Leave a reply or question

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.