We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to print approval Rejected person name on email body

Nani18
Tera Contributor

Hello Experts,

I am trying to print current RITM approval rejected person name in email notification with rejected comments .

but the below script is not working

 

Please correct the script :

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var notes;
var grRITM = new GlideRecord("sc_req_item");
    grRITM.addQuery('sys_id', current.request_item);
    grRITM.query();
    while (grRITM.next()) {
    
    var appr = new GlideRecord('sysapproval_approver');
    appr.addQuery('document_id', grRITM);
    appr.addQuery('state', 'rejected');
    appr.query();
 
    while (appr.next()) {
        var je = new GlideRecord('sys_journal_field');
        je.addQuery('element_id', appr.sys_id);
        je.addQuery('elements', 'comments');
        je.addQuery('name', 'sysapproval_approver');
        je.query();
        if (je.next()) {
            notes = je.value;
        }
 
        template.print('<p>Rejected by: ' + appr.approver.getDisplayValue() + '</p>');
        template.print('<p>Comments: ' + notes + '</p>');
        
    }
}
})(current, template, email, email_action, event);

 

 

Best Regards,

Nani

1 REPLY 1

AniketC85155510
Kilo Patron

Hello @Nani18 ,

 

Please give a try to the code below and see how it works for you.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */ event) {
    var notes;
    var grRITM = new GlideRecord("sc_req_item");
    grRITM.addQuery('sys_id', current.request_item);
    grRITM.query();
    while (grRITM.next()) {
        var appr = new GlideRecord('sysapproval_approver');
        appr.addQuery('document_id', grRITM.sys_id);
        appr.addQuery('state', 'rejected');
        appr.query();

        while (appr.next()) {
            var je = new GlideRecord('sys_journal_field');
            je.addQuery('element_id', appr.sys_id);
            je.addQuery('element', 'comments');
            je.query();
            if (je.next()) {
                notes = je.value;
            }

            template.print('<p>Rejected by: ' + appr.approver.getDisplayValue() + '</p>');
            template.print('<p>Comments: ' + notes + '</p>');
        }
    }
})(current, template, email, email_action, event);

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket