Email script returns record

Annie10
Tera Contributor

Hello,

Currently, we have two approvers (John and David) that approve the RITM.

I would like to get the approver first name using email script and use it in RITM notification.

I'm having an issue where both approvers first name are printing on the same line in the email like this:

Annie10_0-1700175069741.png

 

Could we have one first name print on each email?

 

Here is the email script.  Please help. Thanks

 

Annie10_2-1700175390144.png

 

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

var gr = new GlideRecord("sysapproval_approver");
gr.addEncodedQuery("sysapproval=" + current.getUniqueValue() + "^state=requested");
gr.query();
while (gr.next()) {
template.print(gr.approver.first_name.getDisplayValue()); // Print approver first name
}

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

 

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Annie10 Please update the script as follows.

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

var gr = new GlideRecord("sysapproval_approver");
gr.addEncodedQuery("sysapproval=" + current.getUniqueValue() + "^state=requested");
gr.query();
while (gr.next()) {
template.print('<p>'+gr.approver.first_name.getDisplayValue()+'</p>'); // Print approver first name
}

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

View solution in original post

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi @Annie10,

Template.print is taking both name in same line because there is no line break.

If you want just one name then replace the while with if , this way flow will consider first record's name only.

if you want both name in different line then use the HTML line break tag with template.print("<br/>");

 

while (gr.next()) {
template.print(gr.approver.first_name.getDisplayValue()+"<br/>"); // Print approver first name
}

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Annie10
Tera Contributor

Hello @AshishKM 

Do you have an example where I can capture specific variables from a catalog item into the approval notification table? I'm having a hard time figuring out how to do it. Thank you.

Hi @Annie10,

Open the email notification and check how existing variables are configured, you can add the same way other RITM level variable, only thing , if fields are part of Variable section then Email Script can be use to fetch the data from Variable table for that RITM. Let me know if you have any further question or need help. You can share the notification details and required variable details.

 

-Thanks


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Sandeep Rajput
Tera Patron
Tera Patron

@Annie10 Please update the script as follows.

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

var gr = new GlideRecord("sysapproval_approver");
gr.addEncodedQuery("sysapproval=" + current.getUniqueValue() + "^state=requested");
gr.query();
while (gr.next()) {
template.print('<p>'+gr.approver.first_name.getDisplayValue()+'</p>'); // Print approver first name
}

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