Process approvals using a screen flow in Slack
With the Spring 23 release, screen flows in Slack will be generally available. I set out to explore one use case.
Approvals in Slack are currently possible but have some limitations
- It is only available with the Salesforce for Slack app but not available if you setup one of the cloud specific apps (Sales cloud for Slack, Service cloud for Slack etc.)
- You can only approve or reject but cannot add an approval comment.
I wanted to see if I can improve on that by using a screen flow in Slack. This blog will not cover the initial setup and connection of Salesforce to Slack. You can find details on how to do this in the official documentation.
My solution was inspired by two blogs
- Alex Edelstein created an invocable action for processing approval requests that includes sending an approval comment
- Yumi Ibrahimzade demonstrated how to copy an approval comment from the approval history related list to a field on the record
In order to send a screen flow to Slack you have to create two separate flows that will work together.
- A screen flow – this is what will surface to the user in Slack and process the user inputs there. This flow has to be marked as available in Slack. Marking a flow as ‘Available in Slack’ generates a separate ‘launcher’ invocable action that can be used in other flows
- A record triggered flow – This flow will act as a dispatcher and will use the launcher action, we created in step 1, to send the screen flow to Slack when record conditions are met. Slack actions can only be processed asynchronously, after the record is saved.
To test this, I setup a simple one step approval process, with simple actions that update an approval status picklist field on the record
I then created my screen flow which has only one screen. The screen displays an approval request to the user, along with some record details, and captures the responses. The flow will then use those responses to process the approval using the invocable action, and update the record with the approval comment. The flow has some input variables that will get their value from the dispatching flow. I marked this screen flow as available in Slack. I was not successful in passing a record link to the screen flow. Slack uses a special markup language to format links, which works well when sending a Slack message using the “Send Slack Message” core flow action, but it did not work when sending in the screen flow action.
The next step was to create the record triggered flow that will send to Slack. My trigger was based on a custom Approval status field set to submitted, when a user will submit the record for approval. This will work well for a single step approval process but if you have a multi step process, additional conditions may be needed to determine the current approval step. This flow gets the most recent approval process instance, work item, and approver userId for the triggering record and passes this information, along with the record Id, to the screen flow action.
When both flows are combined, I was able to send an approval request to Slack, process the response, and update the record with the most recent approval comment. Here is a short video of the complete process.
This is a simple use case for a single step approval process with a single approver. It can be enhanced to handle more complex approval processes.
- If there are multiple approvers, the dispatching flow will need to get a collection of all the work items and loop through to send the screen flow to all of them.
- If a queue is set as the approver, the the dispatching flow will need to get a collection of all members of the queue to find their userId
- The screen flow can be updated to add a recall action