Button in SharePoint List to Trigger Microsoft Flow

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.

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.

78 comments

  • Hi Laura,

    Nicely done, but I have a couple of questions.
    1. Does the flow need to have already been shared with the SharePoint list that the flow is acting on?
    2. If yes, what minimum license level for Flow is needed to enable that?

    Like

  • Hi Laura,
    Thanks for this blog, but as always it asks more questions 😉
    I would like to show a button when a document is published. This starts a Flow so that it makes a copy of the document and copies it to the correct language intranet. This flow works well.
    But I do not get the condition right in JSON.
    How do I get this done when Version ends with .0?
    Is this a solution or do I have to think about another way?
    Can you help me with this?
    thanks in advance

    Like

  • Hi can we update a column in sharepoint list on click of a button which we create using column formating

    Like

  • how to run a custom code using JSON button in SharePoint

    Like

  • None of these work when I paste them into my column formatting dialog. It says, “Please enter valid column-formatting JSON.”

    Like

    • If you copied and pasted then the quotes are most likely the wrong characters. Change all the double quotes to double quotes, i.e. ” not “ or

      Like

    • I also can’t get any of these to work when I paste them into my column formatting dialog. Even if I paste them into Notepad first for standard character formatting. What am I missing? I would really like to use this one for the button format, but it always gives “Please enter valid column-formatting JSON.”:

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

      Like

    • Try re-typing your quotation marks. I’ve seen those mess up when copying and pasting.

      Like

    • The basic button snippet has an extra right hand curly-brace too

      Like

    • copy the code and You have to edit “ –> ” then you will get rid of Error

      Like

  • I need to start a Flow from a single button on a SharePoint page. The Flow has a “Manual” trigger. Can you please tell me how I can add it to the “onclick” attribute: <input type="Button" style="background-color:#a7cb00; width:250px;font-size:13pt" onclick="window.location=

    Liked by 1 person

  • In my last comment it looks like the blog software changed my quotes too. In any case, just use a normal double quotes. You have to replace them all.

    Like

  • Hi Laura,

    Good Day.

    I just want to ask a question about your post.

    Is the flow you created can be run by other user who had access to list? or is it only applicable to the owner of the flow itself?

    Thank you in advance.

    TinnyWinnie

    Like

  • Hi Laura,

    Thank you for the quick reply. 🙂
    This is great. I’ll try it on our side.

    Like

  • Hi Laura, I have been able to follow along the instructions with the addition of a button working well. What is not working for me though is the button only showing based on column status – I am not receiving any errors in the json code box its just the button doesn’t appear at all now after extending the code. Is there anything else I need to be aware of when using this? Thinking maybe the format of the column of the status or anything? I feel so close but yet so far to completing this work!!!

    Like

  • Hi Laura, will the option to show button after approval status has been met work on any other field in the SharePoint list or does it have to be the approval field? Sorry for the repeat query, just trying to get it to work!! 🙂

    Like

    • There’s a reference in the JSON to “current field” versus @fieldname. So if you want the logic to use the current field, use that, but if you’re referencing a different field, you have to use the ampersand. I don’t remember the exact syntax off the top of my head, but it’s definitely different.

      Like

  • How do you pass parameters? What is format?

    Like

  • Okay, I’m at a loss. I wrote the following code based on your example and it doesn’t seem to matter what I put in the ButtonVisible field, the button is always visible. I checked to make sure that it has the correct system column name. It does. I thought maybe Visible is a reserved word, so I replaced it with Yay/Nay. That didn’t work. I have no idea why it won’t execute correctly.

    {
    “elmType”: “button”,
    “txtContent”: “Mark Complete”,
    “customRowAction”: {
    “action”: “executeFlow”,
    “actionParams”: “{\”id\”:\”b9437ba0-a6a9-4a72-be9e-277f4604bbc1\”}”
    },
    “visibility”: {
    “operator”: “?”,
    “operands”: [
    {
    “operator”: “==”,
    “operands”: [
    “[$ButtonVisible]”,
    “Visible”
    ]
    },
    “visible”,
    “hidden”
    ]
    }
    }

    Like

    • Update: I figured out that if I add in the code that you added to change the text and background color, it works fine. I was a little worried about that, because I didn’t want a purple button. However, I figured out I can change it to light grey and it looks fine.

      Like

  • Hi,
    I have the buttons working in a list, pretty cool.
    And when the list is viewed on a modern page in a list view web part, the buttons do show.
    But they are not clickable.
    Any thoughts?

    Like

    • I have the same issue. Anybody know of a way to allow the buttons (or really, any of the additional tools) to work in a webpart without having to open the library?

      Like

    • Hopefully Microsoft will fix this little bug. I guess in the meantime we have to make the users do that one little extra click to get to the list / library.

      Like

  • I love finding posts like this. Thank you for the detail.

    Like

  • has anyone yet found a way of doing this with a calendar based list, so not modern view?

    Like

  • If only I’d come to this blog in the first place and found that my Flow had to have a custom trigger!! Every day’s a school day… :o)

    Like

  • Deviprasad Shetty

    Hi Laura,

    I am new Flow workflows and I am creating multilevel approval workflow. In SharePoint Designer workflow we have action Wait for Field change in Current Item. Do we have any similar action like this in Flow workflows.

    Thanks, and Regards,
    Deviprasad Shetty

    Like

  • Hello, this is a wonderful alternative to trigger flows in modern view! I have implemented it on one of my lists and it has been working just splendid! I have one small issue though that I can’t seem to figure out how to fix. When I am creating a new list item, even though I’ve hidden the ‘Action’ column in ‘Advanced Settings’ in the list settings, it’s not visible at first, however when I create a second list item, I see the action column in the form view. It seems like it’s being reset for some reason. Has anyone noticed any similar behavior and can assist with this issue?… Looking forward to a response…

    Like

  • So it seems. However, it leaves the field open to the user who is filling out the form. I guess I can input some custom JS to have it hidden all the time, but, I try to avoid such customization because of how specific the reasons are…
    Thank you for your response 😀

    Like

  • Hi Laura, this is a fantastic post, but I’m having the same problem: Please enter valid column-formatting JSON.
    I’ve changed all quote marks, but can’t see any other issue. What else could be wrong?

    Like

    • Here’s the code again, I just copied it straight from a formatted column in SharePoint:
      {
      “elmType”: “button”,
      “txtContent”: “Get Approved”,
      “customRowAction”: {
      “action”: “executeFlow”,
      “actionParams”: “{\”id\”: \”3fd1d970-0fea-496f-be53-5a8608b382ac\”}”
      },
      “style”: {
      “background-color”: “purple”,
      “color”: “white”,
      “visibility”: {
      “operator”: “?”,
      “operands”: [
      {
      “operator”: “==”,
      “operands”: [
      “[$_ModerationStatus]”,
      “Pending”
      ]
      },
      “visible”,
      “hidden”
      ]
      }
      }
      }

      Like

  • If another user clicks on the button, then opens a form and the flow does not start ??

    Like

  • ok everyone must have authority on the flow …

    Like

  • Hi Laura!
    This helped me out a lot! Thanks! I just have one question. Do you know of a way of hiding the button if the user is not authorized to run the flow. I.e. the user is not in the “run-only” list.

    Like

  • I had this working perfectly. Then suddenly, yesterday, any views that had any JSON formatting on any columns stopped displaying in “new Experience”. I’ve had to delete all those columns to make my data visible again, or I have to swap back to classic which means I can’t use the buttons any more
    I think MS have rolled out something that has broken this

    Like

  • Laura, Thanks so much for this! Since it’s possible to show/hide the button or link based on a column value, is it also possible to trigger two different Flows? So, let’s say there’s a status column with Approved/Rejected/Pending. If an item in Pending, I’d want to run a Flow called “Get Approval”; if it’s Rejected, I’d want to run another called “Submit Appeal”; and if it’s Approved, show nothing. I’m sure this is possible, but my skills (and patience) with json are lacking.

    Like

    • Yes, you can use Flow actions that trigger other flows. So, your button can trigger one Flow, and that Flow can have conditions in it, and each branch of the condition can have actions that start the other Flow(s). These are in the Flow category called ‘Flow Management’.

      Like

  • Can you hide the button for users who have no “run-only” access to the flow? Or maybe hide it from users lacking specific access to the list?

    Like

    • I can’t think of a way, but I don’t know that much about JSON. I know I could do it in a list of things (gallery) in PowerApps, but that’s totally different.

      Like

  • Hi Laura, thank you for the effort you put in teaching us these techniques. I have a question though.. Maybe you can advise.

    We have a “Document Manager” who is responsible for the documents listed in a library. So everyone else, except for the Document Manager, has read only permissions for the items. But the Flow button then disappears. So I came across this article and was hoping to have found the solution to maintain the permissions (read only) and have a button to trigger a specific Flow.

    But the button only works when the user has Any other permission than Read Only. Is there any other way to achieve this?

    Like

    • Well, that’s frustrating! It doesn’t surprise me. No, I don’t know of a way around that. Even when you add them as “run only” users of the Flow?

      Like

    • Yes even with Run Only user permissions. I continued my search and someone advised to give everyone full permission on site level and on library strip the permissions. That should be the workaround.

      But it’s too much hassle to do that now, I’d have to recheck all sites, libraries etc etc if the permissions are still set correctly.

      Like

    • OH right, that’s what had to be done in classic mode, too. So, not new.

      Like

  • Hey Laura, is it possible for the execute flow button to work on a folder/ document set? I want to update the metadata on a document set, but am unable to get the flow to trigger.

    Like

    • I can’t find a way to do that, but I think Document Sets are going to get more love from Microsoft in the coming months, so maybe they’ll add that.

      Like

  • Hi Laura

    It’s a very good post. It was very useful to me.
    I would like to ask you if it is possible to display two different buttons for different Flow in one column, depending on eg the status of the document?
    If the status of the document is “New”, then the “Send to approval” button should be displayed and to start some Flow.
    And if the status of the document is “Approved”, then the “Finish” button should be displayed and to start other Flow.
    And of course, for other statuses, nothing should appear in this column.

    Best regards
    Tomasz

    Like

    • Yes probably. I’ve never personally tried it, but I’m sure you could figure out the logic for that.

      Like

    • Mattias Sandberg

      Hi Tomasz!
      Yes it is possible. I have tried it with success. If you want only one button to be visible at a time then you will need to do though is to set the width of the first button to 0 in case the second button is visible. I have not made this in my test but it shouldn’t be a problem to add that as well.

      {
      “elmType”: “div”,
      “children”:[
      {
      “elmType”: “button”,
      “txtContent”: “Send for review”,
      “customRowAction”: {
      “action”: “executeFlow”,
      “actionParams”: “{\”id\”: \”FLOW GUID\”}”
      },
      “style”: {
      “background-color”: “#279bbf”,
      “color”: “white”,
      “border-radius”: “5px”,
      “margin-top”: “5px”,
      “padding”: “10px”,
      “cursor”: “pointer”,
      “visibility”: {
      “operator”: “?”,
      “operands”: [
      {
      “operator”: “!=”,
      “operands”: [
      “[$axApprovedVersion]”,
      “[$axCurrentVersion]”
      ]
      },
      “visible”,
      “hidden”
      ]
      }
      }
      },
      {
      “elmType”: “button”,
      “txtContent”: “Send for approval”,
      “customRowAction”: {
      “action”: “executeFlow”,
      “actionParams”: “{\”id\”: \”FLOW GUID\”}”
      },
      “style”: {
      “background-color”: “#279bbf”,
      “color”: “white”,
      “border-radius”: “5px”,
      “margin-top”: “5px”,
      “padding”: “10px”,
      “cursor”: “pointer”,
      “visibility”: {
      “operator”: “?”,
      “operands”: [
      {
      “operator”: “==”,
      “operands”: [
      “[$axApprovedVersion]”,
      “[$axCurrentVersion]”
      ]
      },
      “visible”,
      “hidden”
      ]
      }
      }
      }
      ]
      }

      Like

    • I’ve done something similar and it worked fine. Just be aware that in your example if the flow triggered by the “Send to approval” button changes the status of the document from “New” to “Approved”, then the user would need to refresh the page in between triggering the first flow and the second flow. This would make things pretty clunky and there is no current workaround for that.

      Like

    • Just extending the reply from Mattias – you can use the following styles properties to ensure the varying buttons being displayed appear inline with each other:

      “position”:”absolute”,
      “left”:”0″,

      Hope that helps someone.
      p.s. Laura – great post by the way!

      Like

  • As of the update on 3/27/19: When you evaluate the _ModerationStatus column it returns blank instead of “Pending”, “Approved”, or “Rejected”. This makes conditional formatting using the _ModerationStatus column impossible as far as I know. The workaround I used is to create another column that tracks approval status and use that for the conditional formatting of the button.

    Like

  • Hi Laura, Just came across this post. Thanks for putting the effort into putting this together and sharing it. It was very helpful. Like other users I’ve been testing some things and two things I’m trying to figure out. One is that when you click on the button it brings up the “Run Flow” dialog making you click one more time to run the flow. Is there a way around this? The flow is triggered on “For a selected item”. The other thing is that I would like to make it so most users have read only access to the list but can run the flow. The test user has “Edit” access to the O365 group the list is in and “Read” access to the list itself. Even though I have the user added to the “Run Only” users group on the flow, it will not run the flow. Clicking on the button does nothing. Any suggestions?

    Like

  • Hi

    Thank you very much for your article. Everything works really great!

    I have a question concerning visibility: is it possible to make the visibility dependent on two other colums? – E.g.: If the approval Status is “pending” and Customer Status is “active” the button shall be visible.

    Thank you
    Peter

    Like

    • @Peter, indeed it is possible. I had a similar requirement and it took a while figuring it out but hopefully this helps you, and others. What you need to do is clear out the entire “visibility”: {…} section from Laura’s example and replace with something like this (I’ve guessed your internal columns names as approval Status = ‘ApprovalStatus’ and Customer Status = ‘CustomerStatus’):

      “visibility”: “=if([$ApprovalStatus] == ‘pending’ && [$CustomerStatus] == ‘active’, ‘visible’,’hidden’)”

      I’d appreciate it if you (and anyone else) could let me know if this has helped you.

      Like

  • Hi Laura, this is still the best flow article out there.
    Do you know if it’s possible to actually run the flow when user clicks the button instead of opening the “Run flow” form? In cases when there’s no user input required, we just want flow to run right away.

    Like

  • Does anyone know why the column format tells me that the json is not correct ?? Do you have a right json?

    Liked by 1 person

    • If you copied and pasted the code from this post, you need to change the quotes (“) because what gets pasted from your copy is not a standard quote.

      Like

  • Hi Laura – this post opened my eyes. If I want to use the button to send an email, containing values from that particular row where I clicked the button, how would I do that? Right now, when I click the button, with the code you provided, an email is sent per row, from the sharepoint list. The possibilities though….. 🙂

    Like

  • Hi Mam,

    Thank you very much for writing such a great article, i am able to create the same in my development environment.

    just a simple question from my side, is there any Limitation for this button like it won’t work into the List view web-part?

    Issue i am facing right now is Button click does not Triggers the Flow from the web-part as it Triggers inside the SharePoint list.

    Please share your thoughts on it.

    Like

  • Hi Laura,

    Thanks for the post! Can i run multiple flows at a given time using this method? The trigger of my flow is for a selected item and the out of the box method only lets you run one running flow at a time (madness Microsoft!)…

    Like

    • No, unfortunately, it doesn’t work the same way out-of-box. You’d have to do something extra like my post on creating a button in a list/library to run a flow, with conditional formatting so it doesn’t show if already running based on some status field you create.

      Like

  • This really helped me out and was super easy to understand and follow – thanks so much!

    Like

  • Monica.villanueva@glogic.com.co

    Esto solo funciona para ejecutar un flujo de Flow, de designer no?

    Like

  • Hi Laura, We have a classic SharePoint workflow which automatically gets an associated List Column to show the status of the workflow (“In Progress” or “Approved”, etc.) as it should.

    The issue is trying to get the value from that workflow column within our Column Formatting code.

    In your example you used the value from “[$_ModerationStatus]” to decide whether or not to show/hide the button, but seems as though I can’t do this when trying to reference the workflow column. I’m using the internal name of the column but doesn’t seem to get the value.

    Using PnP PowerShell I can get the value. “Approved” is equal to 16.

    Do you know if it’s possible to get this value (“Approved” or 16 – any value would be good enough), when using Column Formatting and a workflow generated column? That way I can only show my button when the workflow isn’t In Progress.

    Like

    • Sorry I’m not sure, I’ve never tried that. I would probably be poking around just like you, trying different things like “16”. There’s some other weird way I’ve seen that column formatted, like #!;Approved or something with weird characters in it like that.

      Like

  • Another great tutorial. I have a couple of questions.

    1. How do I bypass the comment bit when clicked on the button so the flow just starts without the user knowing
    2. Is it possible to bypass the Flow and change the value of another field from Pending to Approved (without Flow)?

    Like

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.