We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Insert the approver in notification linked to the sc_req_item table

Ariomar de Deus
Tera Contributor
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
 
    var approver = new GlideRecord('sysapproval_approver');
    approver.addQuery('sysapproval', current.sys_id);
    approver.query();
    if (approver.next()) {
        out.print("Aprovador Designado: " + approver.approver.getDisplayValue());
    }
 
})(current, template, email, email_action, event);

I am creating a notification in the sc_req_item table, but I need to insert the approver in this notification. As I am unable to do dot walking, I am trying to insert the approver through an email script. When inserting the email script in my notification, it is going blank. I believe my code has an error. Could someone help me with this issue?

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@Ariomar de Deus 

try this

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
 
    var approver = new GlideRecord('sysapproval_approver');
    approver.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);
    approver.query();
    if (approver.next()) {
        template.print("Aprovador Designado: " + approver.approver.getDisplayValue());
    }
 
})(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
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Runjay Patel
Giga Sage

Hi @Ariomar de Deus ,

 

Use below email script and make sure that your ritm should have at least one approval record.

var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', current.sys_id);
    gr.query();
    if (gr.next()) {
        template.print("Approver : " + gr.approver.getDisplayValue());
    }

 

RunjayPatel_0-1735884090919.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

View solution in original post

5 REPLIES 5

Runjay Patel
Giga Sage

Hi @Ariomar de Deus ,

 

Use below email script and make sure that your ritm should have at least one approval record.

var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', current.sys_id);
    gr.query();
    if (gr.next()) {
        template.print("Approver : " + gr.approver.getDisplayValue());
    }

 

RunjayPatel_0-1735884090919.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------