Please help with setSubject in email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 02:00 PM
Hello,
I'm attempting to overwrite the email subject using an email script, but I'm unable to make it work. Please advise.
Here is what I have tried:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 07:35 AM
My apologies for not clarifying which table the email script is written for. This is because I was not familiar with the script, and I did not know what I was doing. The email script is invoked from the email notification on the sc_req_item table.
I was wondering if the following email script is used on the sysapproval_approver table, would it still work the same like it did for sc_req_item table?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 07:03 PM
The script mentioned by you is working for "sc_req_item" only because variables are available on RITM.
if your email script is on another table say "sysapproval_approver" you need to modify the script.
var ritm = new GlideRecord("sc_req_item");
ritm.get(current.sysapproval);
ritm.query();
if(ritm.next()){
subject = ritm.variables.email_subject.getDisplayValue();
email.setSubject(subject);
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 06:55 PM
@Jessica28 Simply update your script as follows.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var RITM = current.document_id.getRefRecord();
var subject = RITM.variables.email_subject.toString();
email.setSubject(subject);
})(current, template, email, email_action, event);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:49 PM
Hello @Sandeep Rajput
I have tried you suggestion code and it did not work.