Trigger Flow on selected Listitem from SharePoint view - create button with JSON column formatting


Can you start a Power Automate Flow on selected SharePoint item? Yes!
You mean, not when an item is created or updated, but on-demand? Yes, of course!

Power Automate gives you a trigger "SharePoint --> For a selected item" using which you can trigger workflow on a selected SharePoint List Item or Document.
You can run the Flow from the ribbon after selecting an item. Additionally, you can even add a button in the view which can be clicked to invoke the Flow.

Below image shows how to run Flow on a selected SharePoint item from the Ribbon. Click anywhere on the list item or document to select it --> Click "Automate" from the Ribbon --> click on the name of your Flow to trigger it.

SharePoint ribbon - run Flow
SharePoint ribbon - run Flow

✌️ Steps to create button in SharePoint view to trigger Flow

Let's assume we have a SharePoint list for projects. Project needs to be approved before it starts execution. We have a workflow (Flow) for approval and should be started when approval button is clicked for corresponding project.
  1. Create a single line of text column 'Approval' in your SharePoint list (or with any other desired name).
  2. Click Column Settings.
  3. Click Format this Column.

  4. SharePoint view - format this column
    SharePoint view - format this column

  5. Paste JSON code given below in the text box.

  6. Make sure you replace value "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" with your actual Flow Id.

    How to find the id of Flow created in Power Automate ?

    Go to Power Automate --> My flows --> Click corresponding Flow --> copy the GUID from the URL after flows/

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "button",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"}"
      },
      "attributes": {
        "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
      },
      "style": {
        "border": "1px black solid",
        "background-color": "orange",
        "cursor": "pointer",
        "margin": "4px",
        "color": "white",
      },
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "iconName": "Flow"
          },
          "style": {
            "padding-right": "6px"
          }
        },
        {
          "elmType": "span",
          "txtContent": "Start Approval"
        }
      ]
    }


    SharePoint column json formattting - button
    SharePoint column json formattting - button

  7. Click Preview to made adjustments as needed. Click Save.
  8. Click button "Start Approval" (you can have your own message on the button) against any list item. This will launch a panel in the right section of the screen with an option to run the flow.
  9. Click "Run flow" to trigger the workflow on selected item.

  10. SharePoint - run Flow on selected item
    SharePoint - run Flow on selected item

⚡️ Conditionally show/hide button in SharePoint view

Is it possible to show the button only when a condition is met, say status=Submitted, and hide the button when a condition is not met?

Yes - add the "visibility" attribute to the "Style" section to update the CSS and toggle the display based value in a given column.
As an example, let us display the button only when the project status is Submitted. Add below line to your JSON code in Style. This checks if the value for Status filed is Submitted and sets the visibility of the button to visible/hidden.

"visibility": "=if(([$Status] == 'Submitted'),'visible','hidden')"


⛔️ InvokerConnectionOverrideFailed error

If you receive below error when clicking on the button, most probably you are using "Manually trigger a flow" trigger in your Flow. Remove the manual trigger and use the SharePoint - "For a selected item" trigger.

Failed to parse invoker connections from trigger 'manual' outputs. Exception: Could not find property 'headers.X-MS-APIM-Tokens' in the trigger outputs. Workflow has connection references '["shared_wordonlinebusiness","shared_sharepointonline"]' with invoker runtime source.



Have Questions? Post them here!


















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap