You need to sign in to do that
Don't have an account?
Pull approval process comment to customized report
trigger pullCommentsApproval on Return_Shipment__c (before update) { if(trigger.isUpdate){ List<Return_Shipment__c> opptyList=[Select id, (Select Id, IsPending, ProcessInstanceId, TargetObjectId, StepStatus, OriginalActorId, ActorId, RemindersSent, Comments, IsDeleted, CreatedDate, CreatedById, SystemModstamp From ProcessSteps ORDER BY CreatedDate DESC) From Return_Shipment__c WHERE Id IN : Trigger.new]; if(opptyList.size() > 0){ for(Return_Shipment__c opp : opptyList){ for(Return_Shipment__c opp1 : Trigger.new) { if(opp.id == opp1.id&& opp1.Final_Approved__c) { if (opp.ProcessSteps.size() > 0) { opp1.Approver_Comments__c = opp.ProcessSteps[0].Comments; opp1.Approver_Comments1__c = opp.ProcessSteps[1].Comments; opp1.Approver_Comments2__c = opp.ProcessSteps[2].Comments; opp1.Approver_Comments3__c = opp.ProcessSteps[3].Comments; opp1.Approver_Comments4__c = opp.ProcessSteps[4].Comments; } } } } } } }
Here is the output:
As for now, I have 5 object fields to capture approval comments. One approval, one comment field. However, in real life, it is not necessary for all 5 people to need to approve the form. But this code won't show the comments until the fifth person approves them.
How I can alter this code to make no matter how many (max 5) people approve the form, the comments are still will be there (in the report?) For example, let say a form needs to be approved by 3 people, so all three comments will be shown in the report.
Final_Approved__c is a check box to ask approval is it she/ he is the final approval.