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.

37 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

  • 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=

    Like

  • 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 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

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.