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.

How to set notification subject through email script

prasad8
Giga Expert

I have to set approval rejected user to populate in email notification. Notification i have written on Change_request table.

Here my script:


appr = new GlideRecord('sysapproval_approver');
appr.addQuery('state', 'rejected');
appr.addQuery('sysapproval', current.getUniqueValue());
appr.query();
if (appr.next()) {
template.print(appr.getDisplayValue('approver'));
email.setSubject(approver);
}

 

It displaying user name in email body, but in subject line it is not working. Can any one help me on this.

1 ACCEPTED SOLUTION

Replace 

email.setSubject(sysapproval.number +"Rejected by " + approverName);

with

email.setSubject(appr.sysapproval.number +"Rejected by " + approverName);

View solution in original post

8 REPLIES 8

Hi @Sagar Pagar ,

 

I have added this script and it is working, but in the email subject line i need "${number} Rejected by ${mail_script:change_rejecter}". Number is not displaying.

here my script:

var approverName = '';

appr = new GlideRecord('sysapproval_approver');
appr.addQuery('state', 'rejected');
appr.addQuery('document_id', current.getUniqueValue());
appr.query();
if (appr.next()) {
template.print(appr.getDisplayValue('approver'));
approverName = appr.getDisplayValue('approver');
email.setSubject(sysapproval.number +"Rejected by " + approverName);

}

 

for number try this - ${document_id.number}

Rejected by ${approver.name}

 

Thanks,
Sagar Pagar

The world works with ServiceNow

prasad8
Giga Expert

Hi @Ankur Bawiskar

 

Could you please help me on this. I am facing issue with populating change number in the subject line.

Here is my mail script:

 

var approverName = '';

appr = new GlideRecord('sysapproval_approver');
appr.addQuery('state', 'rejected');
appr.addQuery('document_id', current.getUniqueValue());
appr.query();
if (appr.next()) {
template.print(appr.getDisplayValue('approver'));
approverName = appr.getDisplayValue('approver');
email.setSubject(sysapproval.number +"Rejected by " + approverName);

}

 Help me on this issue

 

Thanks,

Prasad

Replace 

email.setSubject(sysapproval.number +"Rejected by " + approverName);

with

email.setSubject(appr.sysapproval.number +"Rejected by " + approverName);