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
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  ||  ✨ 9x 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

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on
5 REPLIES 5

Ankur Bawiskar
Tera Patron
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  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

didn't work, the approver doesn't appear in the notification  

Hello @Ariomar de Deus , Good Day! I have tired your script in the explore with the sys-id in the query directly and it returns the approver name as expected. [ gs.print("Aprovador Designado: " + approver.approver.getDisplayValue());]

 

(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()) {
        template.print("Aprovador Designado: " + approver.approver.getDisplayValue());
    }
 
})(current, template, email, email_action, event);

Could you please once add the logs in your script and try to trigger the notification on lower environment and verify the logs what exactly you are getting over there. (Observation: out.print is used intead template.print)

Please do let me know if it helps you and feel free to share your results if it is not working.

Thanks,

Priyanka R

@Ariomar de Deus 

the script I shared should work fine.

what debugging have you done so far?

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

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