SharePoint column formatting allows users to customize the way data is displayed in list columns using JSON (JavaScript Object Notation). This feature enhances the visual presentation of data, making it easier to interpret and interact with information.
Steps to Create a Button to Trigger a Workflow
Step 1. Create a Button Column
- Open your SharePoint document library.
- Click on + Add column and select Single line of text or Choice (name it something like "Approve Document").
Step 2. For adding Approval Status column, we have to change some library settings.
2.1 Go to Library settings and going into Advanced Settings, we need to allow management of conetent types.
2.2 Then, going in versioning settings, we need to click on "yes" for content approval for submitted items. Then click on the "Ok" button at the end of the page.
2.3 After that you can add Approval Status column to Library view.
Step 3. Access Column Formatting
- Click the dropdown arrow next to the newly created column header.
- Select Column settings and then Format this column.
Step 4. Add JSON Formatting for the Button
In the formatting pane, use the following JSON code to create a button that can be styled to trigger the approval flow. Note that the onclick
functionality will need to link to the Power Automate flow or a custom action:
Step 5. Paste the following code in the panel as json
{
"$schema": "https: //developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
"elmType": "button",
"txtContent": "Get Approved",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\":\"your flow ID\"}"
},
"style": {
"background-color": "black",
"color": "white",
"visibility": {
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
"[$_ModerationStatus]",
"Pending"
]
},
"visible",
"hidden"
]
}
}
}
Finally, By Clicking the button you can trigger the flow. Your workflow will be of manually triggered flow. You can get the flow ID by clicking flow identifier as shown in below images
Conclusion
By following these steps, you can create a button in a SharePoint document library that triggers an approval flow in Power Automate. This setup allows users to initiate approval processes directly from the document library interface, streamlining workflows.