Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need help with email script.

Keang
Tera Contributor

Hello,

The following email notification is for Change Request and it is triggering from sysapproval_approver table with an email template. 

 

Keang_0-1724097396438.png

 

However, it is missing Request By name on the notification.

I tried to capture it in the email script, but it is returning "null" value:

 

 

 

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

    var gr = new GlideRecord("change_request");
    gr.get(current.sys_id); // Replace 'your_sys_id_here' with the actual sys_id value
    template.print(gr.getDisplayValue('requested_for'));



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

 

 

 

1 ACCEPTED SOLUTION

Saloni Suthar
Giga Sage
Giga Sage

Please modify your script: 

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

    var gr = new GlideRecord("change_request");
    gr.get(current.sysapproval); // Replace 'your_sys_id_here' with the actual sys_id value //sysapproval field has the sysid of the change request
    template.print(gr.getDisplayValue('requested_by')); 



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

If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

View solution in original post

2 REPLIES 2

Swapnil24
Giga Guru

Hi @Keang , your screenshot says requested by but your script says requested_for. requested_for does not exist on change_request table.

Thanks,

Swapnil Deo

Saloni Suthar
Giga Sage
Giga Sage

Please modify your script: 

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

    var gr = new GlideRecord("change_request");
    gr.get(current.sysapproval); // Replace 'your_sys_id_here' with the actual sys_id value //sysapproval field has the sysid of the change request
    template.print(gr.getDisplayValue('requested_by')); 



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

If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni