Ankur Bawiskar
Tera Patron

Hi,

update as this -> your notification and email script is on sysapproval_approver

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

    var record = new GlideRecord('sc_req_item');
    var sysCurrentRecordSysId = current.sysapproval;
    record.addQuery('sys_id', sysCurrentRecordSysId);
    record.query();
    if (record.next()) {
        var obj = JSON.parse(record.variables.request_information); //update with your variable set name
    for(var i=0; i<obj.length; i++) {
    template.print('<br/>' + 'System: ' + obj[i].system_name); 
    template.print('<br/>' + 'Profile: ' + obj[i].profile_name);
    template.print('<br/>' + 'Approver: ' + obj[i].aprovador_do_perfil);
        }
    }
}

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur, Thanks for this solution,

Its working but for "system_name" and "profile_name" is returning the Sys_ID, any idea how can i get the name for this variables?

@NIcollas Viggiano 

Glad to know.

For that sysId you need to query the table being referred by that variable and then get the display value

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

    
    var record = new GlideRecord('sc_req_item');
    var sysCurrentRecordSysId = current.sysapproval;
    record.addQuery('sys_id', sysCurrentRecordSysId);
    record.query();
    if (record.next()) {
        var obj = JSON.parse(record.variables.request_information); //update with your variable set name
        for(var i=0; i<obj.length; i++) {

            var rec = new GlideRecord('tableReferredBySystemName');
            rec.get(obj[i].system_name);

            var rec1 = new GlideRecord('tableReferredByProfileName');
            rec1.get(obj[i].profile_name);

            template.print('<br/>' + 'System: ' + rec.getDisplayValue()); 
            template.print('<br/>' + 'Profile: ' + rec1.getDisplayValue());
            template.print('<br/>' + 'Approver: ' + obj[i].aprovador_do_perfil);
        }
    }
}

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

Thanks Ankur, now its working perfectly.

Hello Ankur,

Hope your doing well.
I am trying to print both variable and multiple row variable set data on the approver email notification.
can you help me with this?