Using Flow to Save Approval Information to Record Fields

Using Flow to Save Approval Information to Record Fields

Approval process is an automation tool that lets users approve records in Salesforce. An approval process can have one or more steps. Using the steps, it is possible to request approval from users and define what to do at each step of the process. You can add actions to initial submission, approval steps, final approval, final rejection, or recall. However, there are only four supported actions.

  • Email alert: Send an email to a recipient using an email template.
  • Task: Create a task record to a specified user.
  • Field update: Update a field of the record.
  • Outbound message: Send a message to a designated endpoint.

If you are familiar with workflow rules, you can see that these are the same actions that are supported by workflow rules. If you want to perform an action that is not listed here, you can perform it by triggering another automation tool. Since Process Builder and Workflow Rules will be retired in the near future, flow is the best option here. Read this post to learn more about the retirement process of these automation tools.

Even though there is an option to update fields, it is very limited. It doesn’t support using values from the process, including the approval or rejection comments. In order to update a field with a value from the process, you have to use a flow. However, how can you trigger a flow from an approval process? Actually, it is simple. You have to update a field and this field update should be the trigger of the flow.

Let’s see an example of saving the approval comment to a field on a case record.

Saving the Approval Comment to a Field on Case Record

Add an Approval Action to the Approval Process

Let’s assume that there is an approval process for the case object. In order to trigger the flow, you have to add a field update as the approval action of the process. In this example, there is only one step in the process and the goal is to save the approval comment. If you need to do the same for more steps or also for rejection, just add a specific action to trigger the flow.

Final approval action

As you can see, at the end of the approval process, there is a field update to mark a checkbox field on the case record. Make sure that you mark “Re-evaluate Workflow Rules after Field Change”.

Field update for approval process
Create a Record Triggered Flow to Save the Approval Comment

Starting with the Spring ’22 release, field changes made by approval processes can run record-triggered flows. Before this release, you had to use a Process Builder in order to trigger your autolaunched flow. Since it is a new feature of the Spring ’22 release, pay attention that you are using API version 54 or higher. Read this post to learn more about this change and the other great features of Spring ’22 release.

1- Create a record-triggered flow. Select case as the object and enter the checkbox field as the criteria. Make sure that the flow runs on update and only when the record is updated to meet the condition requirements.

Depending on your needs, you can make it an after-save flow by selecting “Actions and Related Records”. However, in this example you will just update a field on the same record. So, “Fast Field Updates” is a better option for this example.

Flow start configuration
Flow start conditions

2- Add a Get Records element to get the last Process Instance record related to the case. This is the record that stores the approval process information related to the case.

Get Process Instance

3- Just to make sure, add a Decision element to check if there is a Process Instance record related to the case. Otherwise, there is no reason to continue the flow.

Decision to check the Process Instance for Approval Process

4- Add a Get Records element to get the Process Instance Step related to the Process Instance that you found. This object stores the information of the approval step status related to the approval process. Add another criteria to get the record that has Approved StepStatus. This criteria is needed because the goal is to save the comments that the user wrote while approving. If you want to do it for rejection as well, add a criteria with StepStatus equals to Rejected.

Get Process Instance Item

5- Add a Decision element to check if Process Instance Step exists. If not, there is no reason to continue the flow.

6- Add an Update Records element to update the case record. Comments are stored in the Comments field of the Process Instance Step record. If you need more information such as the approver, you can find the user Id in the ActorId field of the Process Instance Step record.

In order to save the date/time and keep the existing value in the field, create a formula.

Formula to save approval comment
Update case record with approval comments
End of the Flow

This is the end of the flow. Make sure that you activate the flow after saving it. Your flow should look like this.

Record-triggered flow
Approval comments on the record

Since you are triggering a flow, it is possible to perform any kind of actions. You can create, update or delete any record in the system. You can send custom notifications, or post on Chatter, or anything that you need. So it means that, even though the approval process support only four type of actions, it is possible to extend the possibilities using a flow.

8 Comments

  1. I have created the same flow in my org and instead of update I am creating records.While debugging no errors found but the record is not created.

    Can you help with this?

    • Hi,

      Can you make sure that your flow is using the API version 54? Also, make sure that you marked “Re-evaluate Workflow Rules after Field Change” on your field update from the Approval Process.

  2. Very helpful information. In this example, the ‘reset’ field is checked TRUE indefinitely. How would you support multiple approval steps or resubmissions for approval?

    • Hi Ken,
      You just need an indication to trigger the flow. If you have multiple steps or multiple approvals, you can still mark the checkbox when the record is approved. But then unmark the checkbox in the same flow, so that you can use the same logic over and over again.

  3. I am trying to do this with two approval steps but I only get comments to populate from the last step of the approval, any suggestions?

    • Hi,

      In my example I got the first record only but I think you need to get all the records and then use a loop with assignment element.

Leave a Reply

Your email address will not be published.


*