List formatting conditionally display different actions to call a power automate flow
Introduction
In SharePoint, you can enhance user interactions by conditionally triggering different Power Automate flows based on specific conditions in a list or library. This is achieved using JSON column formatting and the executeFlow
action. By dynamically linking flows to specific conditions, you can streamline processes and improve automation.
List formatting provides a powerful feature to control the flow of a process from filling mandatory fields, create approval tasks. Depending on the status of the list item, different power automate flows can be called.
Prerequisites
Before proceeding, ensure you have the following:
- Power Automate Flows: Create the flows you want to trigger. Note the GUID of each flow. You can find the GUID in the flow’s URL:
https://us.flow.microsoft.com/manage/environments/Default-
The <flow-guid>
is the unique identifier for your flow.
- Run-Only Permissions: Ensure the flows have run-only permissions configured. You can add users, groups, or SharePoint lists/libraries to allow them to trigger the flows without editing them.
JSON Column Formatting to Trigger Flows
The following JSON code demonstrates how to conditionally call different flows based on the value of a column (e.g., Status
) in a SharePoint list or library.
JSON Code Example
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"customRowAction": {
"action": "executeFlow",
"actionParams": "='{\"id\": \"' + if([$TrackingStatus]=='New','1811db3a-d75e-40c4-9c5f-6b303e4800c5',if([$RequestValidation]=='Validated' && [$RequestAuthorisation]=='Pending','99fc6be7-1695-4743-bfc0-77de87ae5079',if([$RequestAuthorisation]=='Authorised' && [$FinanceProcessingDate] && [$TrackingStatus]!='Completed','668ff0ab-c0b0-4524-8a86-87c15ada588e',''))) + '\"}'"
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
},
"style": {
"border": "none",
"background-color": "transparent",
"cursor": "pointer",
"text-align": "left",
"display": "=if([$TrackingStatus]=='New','block',if([$RequestValidation]=='Validated' && [$RequestAuthorisation]=='Pending','block',if([$RequestAuthorisation]=='Authorised' && [$FinanceProcessingDate] && [$TrackingStatus]!='Completed','block','none')))"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "Flow"
},
"style": {
"padding-right": "6px"
}
},
{
"elmType": "span",
"txtContent": "=if([$TrackingStatus]=='New','Submit for Validation',if([$RequestValidation]=='Validated' && [$RequestAuthorisation]=='Pending','Submit for Authorisation',if([$RequestAuthorisation]=='Authorised' && [$FinanceProcessingDate] && [$TrackingStatus]!='Completed','Submit for Sign-Off','')))"
}
]
}
Display Button Based on Content Approval Status
To display the button only when the content approval status is “Pending”, you can use the following JSON code in the Format Column panel:
JSON Code for Conditional Visibility
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"style": {
"visibility": "=if([$ModerationStatus] == 'Pending', 'visible', 'hidden')"
},
"txtContent": "Approve"
}
Explanation
The visibility property uses a condition to check if the ModerationStatus column equals Pending. If true, the button is visible; otherwise, it is hidden.
Conclusion
By using JSON column formatting and the executeFlow action, you can dynamically trigger different Power Automate flows based on conditions in a SharePoint list or library. This approach enhances automation and improves user experience by providing context-sensitive actions.