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.

33 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.

      • Can you please show the full value you are putting in filter criteria.In the screenshot,it is not coming the full value inside value filter criteria.Like to check processinstancestep exist or not ,full filter criteria is not given ,if we sleect processinstance in filte then which related field needs to be sleected

        • Hi,
          You don't need to select a specific field from the record.
          Just select the result of the get element. I know that it will ask you to select a field but just click somewhere else, so that you won't select a field.
          Then check if it is null or not.

  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?

  4. Hi!
    This is awesome!
    I'm just trying to use the Process Instance to send an Email alert to the Submitter of the request that their request has been approved. So, how do I integrate that into the trigger. Please your guidance will be much appreciated.

    Thank you.

    • Hi,

      I think you can just use the approval action from the approval process. I don't think that you need a flow for this, unless you have a complex requirement.

      • Hi Yumi!
        Thank you for your response.
        The problem is Salesforce does not have the functionality to send a notification email to the submitter of a record for approval.
        When creating an Email notification within an Approval Process, there is no way to designate the user who submitted the record for approval as a possible recipient of the Email Alert. Currently, the only options are the Record Owner, Created By, Last Modified By, and the standard specific User, Public Group, or Role and Subordinates. It would only make perfect sense that the user who submitted the record for approval would like to be notified when/if the record is approved or rejected.
        I need to be able to send an email alert to the user who submitted the record for approval

        Thank you for your guidance.

        • This is what someone suggested to me:
          To send an Email Alert, look into using a record-triggered flow on the Journal object with an entry criteria of Approval Status = ‘Approved’ that then queries (gets) a “Process Instance” record where TargetObjectId = $Record.Id and Status = ‘Approved’
          I have used this before until I read your blog. But I still don't how to about using to send an email alert to a submitter.

          • Correct. In this case you cannot use an email alert because you define the recipients on the email alert level (not in the flow), but you don't know the submitter.
            I think instead of an email alert, you can use the send email core action of flow. You can create the email body in a text template, get the submitter's email address and put it to the recipient email addresses list (it is an input value for the send email action).

  5. Hi Yumi!
    You are just awesome! This is exactly the directions that I've been looking for. No wonder my alert didn't work when I did it the first time. Your solution works perfectly, I didn't even think I could use the SF send email core action
    Please keep up the amazing work and don't stop posting great stuff here.

    Thank you.

  6. Hi Yumi, I have a requirement wherein I need to update a field when approver is reassigned. Is this possible?

    • Hi,
      I think it is not possible. You can run a flow when a request is approved, rejected, or recalled (using the actions from the approval process). However, since it is not possible to add an action when the approver is reassigned, I think you cannot run a flow.

    • Hi Sreeni,
      It is unfortunately not possible to do that. Even if you mark a checkbox that triggers a validation rule, since the main field update is from an approval process, it skips the validation rules.

    • It skips the validation rules but you can use the standard system validations. For example, try to update a lookup field with "You must fill the comments!".
      Since it is not a valid value for a lookup field, it will give you an error including this text.
      For example I tried it and used a lookup field called "Account Manager". This is the message that the user gets:
      Account Manager: id value of incorrect type: You must fill the comments!

  7. This is fantastic, thank you for posting! Everything seems to be working for me except the formula. This is the formula I'm using:
    LEFT( TEXT( {{!$Flow.CurrentDateTime} ),16)&": "&{!Get_Process_Instance_Step.CreatedBy.Alias}&" - "&{!Get_Process_Instance_Step.Comments} &BR()&{!$Record.Approver_Comments__c}
    The date and alias are pulling through, but no comments. I thought maybe it wasn't working because I'm approving via email, but it also doesn't work when I approve directly on the record. I confirmed I'm on the latest API version. Any thoughts?
    Thank you!

    • Hi,
      Your formula looks correct but maybe it is not bringing the correct Process Instance Step record. Can you check that record using its Id? You can write a query in developer console or just navigate to that record to see if there is a value in the comments field.

  8. Hi Yumi. I have a requirement to save approval comments from multi level approvers not only the final approver. How can I do that ?

    • Hi,
      Instead of getting the first Process Instance Step, you can get all the records that meet the criteria. This will store them in a record collection. Then you have to use a loop and assignment to prepare a variable that contains all of the comments.

  9. Hello, I'm developing the flow but I have an error in the part of {!Get_Process_Instance_Step.Comments} "The field "Comments" does not exist in the object "ProcessInstance" or you do not have access to the field.". I am system admin, what can it be??

  10. HI,
    How to use flow to automate and to put the "previous value" of your picklist in each time it is changed. Then when your approval is rejected use your automation to grab your previous value field and set your picklist value with you. I need when rejected the value to go back to the previous. What are the steps to achieve this?

    • Hi,
      It needs to know what the previous value is. So, I can think about 2 possible solutions.
      1- Save the previous value to another field. If the approval is rejected, you can use a flow to take the value from that field.
      2- If the approval is rejected, use the Get Records element to bring the previous value from the history (for example, AccountHistory). In order to do this, you have to enable field tracking for that field.

  11. Hi
    I have 2 step approval process and there are field updates in both of them. When record is approved, the field is updated and the flow also runs. But the flow is not able to get the latest ProcessInstanceStep where Status = Approved. It is getting the one with Status = Started only.
    When I again update the value manually, it is able to fetch the latest 'Approved' ProcessInstanceStep.

    • Did you build the flow to work after the approval process? I mean the approval process should update something (when it's approved), then this field update should be the entry criteria of the flow.

1 Trackback / Pingback

  1. Process approvals using a screen flow in Slack – UnofficialSF

Leave a Reply

Your email address will not be published.


*