function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LIM AI KHOONLIM AI KHOON 

Pull approval process comment to customized report

Hi, currently I want to pull comments from the approval process form to a report. Here is my code:
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:
User-added imageAs 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.

Mona LizaMona Liza
how can works this code? (https://lite14.me/)Please.Thanks