Pages

Tuesday, April 26, 2016

Salesforce: Store Approval Comments to Notes

Use Case: we need to capture Comments type by approver when approve or reject in Approval process as Notes.

Assume that you already have the following:
- Status picklist field: Draft, In Progress, Rejected, Approved
- Approval Process with actions to update status to Rejected or Approved

Solutions:
1. Process Builder 
Process to trigger when the status change to Approved or Rejected

a. Select the object and make sure to select "when a record is created or edited"
b. Criteria: make sure both values captured with OR logic

c. Action: call Flow with passing Record Id as flow variable


2. Autolaunched Flow
Flow designer:

a. Lookup to Process Instance object, filter to Record Id and Approval Process Id, you need to store Approval Process Id into a constant.
Store the result (Id and Status) to a sobject variables, as this will always return only 1 record, we can use Sobject Variables.

b. Lookup to Process Instance Step object, filter to Process Instance Id, Step Status equal to Rejected and Approved. Store the result (Comments, StepStatus, and ActorId) to a sobject Collecton variables, this lookup may return more than 1 record, so we should use Sobject Collection Variables.

c. Loop the Process Instance Step object
Copy each record from Sobject Collection Variables to Sobject Variables.

d. Assign Sobject Variables
Populated fields to a new Sobject Variables.

formulaBody is a formula resource = {!lvProcessInstanceSteps.ActorId} & " | " &
 TEXT({!lvProcessInstanceSteps.StepStatus}) & " | " &
{!lvProcessInstanceSteps.Comments}
Approval Comment is just a text for note title.

e. Assign Sobject Collection Variables
Add Sobject Variables to new Sobject Collection Variables

f. Create Notes


So, when it is approved / rejected, a note will be automatically created.


Here is the notes content:


With slight adjustment in the Flow, you can change the flow to store approval history into a custom object.



3 comments:

  1. Hi Johan,

    I'm curious as the reason behind why you would want to capture comments in the notes object if the approval process already does this for you? - Is there a limitation on comments within the approval process?

    Best Regards,
    Richard

    ReplyDelete
    Replies
    1. Hi Richard, I cant really remember the use case 4 years ago, but probably related to reporting.

      Delete
  2. You cannot pull comments into a report.

    https://trailblazer.salesforce.com/ideaView?id=08730000000l7s0AAA

    ReplyDelete