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

Sagar Pagar
Tera Patron

Hi,

You can use ${approver} in email subject

for example -

${sysapproval.sys_class_name} ${sysapproval} has been rejected by ${approver}

 

OR try this updated script.

var approverName = '';

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

}

 

Thanks,
Sagar Pagar

The world works with ServiceNow

HI Sagar, 

 

I changed my script, still it is showing like below.

find_real_file.png

 

When i preview my notification subject is showing like thisfind_real_file.png

 

 

Just try with

${number} Rejected by ${approver}

The world works with ServiceNow

I have tried this but it is populating wrong user name. Ex:  I have group approval if any one approves it needs approve. if 'A' rejects from the group i need to populate 'A' name. right now it is displaying other name.

 

thanks,

prasad