Trigger MS Flow On SharePoint List Items Based On Column Formatting

In this article, we will learn how to add an action button on the list items view using column formatting which will trigger an MS Flow based on some conditions. This article will cover the below use cases. 
  • Usage of column formatting to add an action button.
  • Trigger MS flow from list item view's action button.
  • MS flow to get user input before MS flow starts.
The first thing we will do is to setup MS Flow for our example. We won't go into details of how to create a Microsoft Flow as there are a lot of articles available to cover this topic. Some of them are mentioned below.

MS Flow Setup - Step 1

 
I have created an MS Flow with trigger point as 'For selected items'. Below is the configuration of the triggering point. We have added two optional input fields using the 'Add input' button as marked below in the screenshot.
 
Trigger MS Flow On SharePoint List Items Based On Column Formatting
 

MS Flow Setup - Step 2

 
The next action item is to send mail, (you can ignore GetmyProfile action item from the above screenshot for this example). In this action Send Mail, we will send email to a particular user and add input forms entered by the user in the email body. Below is a screenshot for your reference.
 
Trigger MS Flow On SharePoint List Items Based On Column Formatting
 

MS Flow Setup - Step 3

 
Save MS Flow. The next item is to get the MS Flow ID which will be used later in the column formatting step. On the "Edit MS Flow" page, we will get MS Flow ID in URL. For example, for the above flow, below was the URL (obviously, changed GUIDs).
 
https://india.flow.microsoft.com/manage/environments/Default-5b9dueb0-1ek3-46psd-8da3-6ba895467b9/flows/2abcd334-z897-460a-92s8-461d43p97fd0 
 
Text marked in red is your MS flow id. Note it down.
 
Now, let us set up our list to be used for this example.
 

Setup List  - Step 1

  • Create a List named 'CustomList'  
  • Add Status column as a choice with 'Pending', 'In progress' and 'Completed'
  • Add StartFlow column as a calcuated column with formula ="". Here, we are setting up a dummy column as we will be using other fields to populate values in this field. 

Setup List - Step 2

 
Next, we will use column formatting options to format our StartFlow column. Edit column again and paste the below JSON value in column formatting options.
 
Trigger MS Flow On SharePoint List Items Based On Column Formatting
 
Let us understand what are we doing here in JSON.
  • We are using customRowAction with action executeFlow and passing actionParams to pass the id of MS flow(as noted in above step)

    Note
    Here, we are using Excel-based expression to check Status column value and passing id accordingly. For this example, I am passing the same id for all the cases. This to demonstrate we can trigger different flow based on fields values.
  • Next thing we are doing here is based on Status columns value, formatting font colors with attributes.
Then, we are adding text and icon. Again, here we are using conditional formatting to display different icons and text based on the Status column's value.
  1. {  
  2.   "$schema""https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",  
  3.   "elmType""button",  
  4.   "customRowAction": {  
  5.     "action""executeFlow",  
  6.     "actionParams""='{\"id\": \"' + if([$Status]=='Completed','2cabd779-a135-420a-90f8-461d56e83fd0',if([$Status]=='Inprogress','2cabd779-a135-420a-90f8-461d56e83fd0','2cabd779-a135-420a-90f8-461d56e83fd0')) + '\"}'"  
  7.   },  
  8.   "attributes": {  
  9.     "class""='ms-fontColor-' + if([$Status]=='Inprogress','redDark', if([$Status]=='Completed','teal','orangeLight'))"  
  10.   },  
  11.   "style": {  
  12.     "border""none",  
  13.     "background-color""transparent",  
  14.     "cursor""pointer"  
  15.   },  
  16.   "children": [  
  17.     {  
  18.       "elmType""span",  
  19.       "attributes": {  
  20.         "iconName""=if([$Status]=='Completed','Checkmark',if([$Status]=='Inprogress','ProgressLoopInner','Important'))"  
  21.       },  
  22.       "style": {  
  23.         "padding-right""6px"  
  24.       }  
  25.     },  
  26.     {  
  27.       "elmType""span",  
  28.       "txtContent""=if([$Status]=='Completed','Thanks',if([$Status]=='Inprogress','Send Reminder','Send OverDue Mail'))"  
  29.     }  
  30.   ]  
  31. }  
Note
Other supported customRowAction values are,
  • defaultClick - opens the information panel (same as clicking on an item)
  • share - opens the sharing dialog for the item
  • delete - opens the delete confirmation dialog for the item
  • editProps - opens the item properties page in edit mode
  • executeFlow - launches a specified flow for the item (the Flow ID is specified in the actionParams attribute)

Setup List - Step 3

  • Add some dummy data to list with different values in status columns.
  • Go to list view to check the output. Below is what you should see.
    Trigger MS Flow On SharePoint List Items Based On Column Formatting

Testing - Step 1

 
Now let us see how to check what happens when the user clicks on the button. Go to list view (as in the above screenshot). Click on any list items action item. As our MS Flow takes user inputs, it will open the below window. Enter email id and custom message and click on Start Flow.
 
Trigger MS Flow On SharePoint List Items Based On Column Formatting
 
It should start flow, go to MS flow platform to check flow status.
 
https://india.flow.microsoft.com/manage/environments/Default-5b9dueb0-1ek3-46psd-8da3-6ba895467b9/flows/2abcd334-z897-460a-92s8-461d43p97fd0/ details
 

Testing - Step 2

 
Go to your email and check email.
Trigger MS Flow On SharePoint List Items Based On Column Formatting
 
In this article, we have seen how to add action button on list items view using column formatting which will trigger MS flow based on some conditions.