How to get the reference record for Group approvals?

ArpitaVK
Tera Expert

I have a Notification 'Approval request for exception' which is OOB on Approvals [sysapproval_approver] table. It contains the Notification email script 'sn_vul_exception_request_to_group'. Now, that I have changed the Notification table to Group Approval [sysapproval_group], the body of Notification is now blank as it is not getting any reference record. 

var appr_Record = current.document_id.getRefRecord();
var vul_record = appr_Record.vul_record.getRefRecord();
These are the two lines from where it was getting the reference record. Now that I have changed the Notification table to Group Approval [sysapproval_group], how can I get the reference of the record for which approvals are getting created?
5 REPLIES 5

M Ismail
Tera Guru

Hi @ArpitaVK ,

Here in this line of code var appr_Record = current.document_id.getRefRecord();
document_id is the field on sysapproval_approver and we don't have this field on sysapproval_group table so you would have to replace this line of code with this 
var appr_Record = current.parent.getRefRecord();
means from approval record we are reaching out to the record for which we have approval, means apporval for change request or approval for requested item etc.
Please hit helpful and accept this as a solution if it solved your problem.
Thank you!

Hi @M Ismail 

Parent is showing empty for group approval records.

@ArpitaVK Can you please give me a full code.

(function runMailScript(current, template, email, email_action, event) {

    var subject, body, vulRecordLink, reqDetails, vulDetails;
    var util = new VREmailUtils();

    var appr_Record = current.document_id.getRefRecord();   
    var vul_record = appr_Record.vul_record.getRefRecord();

    vulRecordLink = util.getVulLink(vul_record);
   
   var approversArr = appr_Record.approvers_list != '' ? appr_Record.approvers_list.split(","): '';
   
    body = gs.getMessage("Hi Exception Approver,<br/><br/>An exception request has been submitted by {0} on {1} to defer {2}.<br/><br/>Please review and approve this request as soon as possible. Additional details are as follows:<br/><br/>", [util.getUserName(appr_Record.requested_by), '${sys_created_on}', vulRecordLink]);
    template.print(body);
   
    if(approversArr.length > 0){
        appDetails =  gs.getMessage("Approver name: {0}<br/><br/>", [util.getUsersName(approversArr)]);
        template.print(appDetails);
    }

    reqDetails = util.getRequestDetailsForException(appr_Record);
    template.print(reqDetails);

    vulDetails = util.getVulnerabilityDetails(vul_record);
    if (vulDetails) {
        template.print(vulDetails);
    }

})(current, template, email, email_action, event);