Please help with setSubject in email script

Jessica28
Tera Guru

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:

 

(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;
    email.setSubject(subject);
})(current, template, email, email_action, event);
 
It is printing out "Undefined" on email subject
 
Jessica28_0-1697662787406.png

 

 

8 REPLIES 8

Jessica28
Tera Guru

Hello,

Please discard my answer.  I was able to figured out how to get it to works. 

Thank you

Prince Arora
Tera Sage
Tera Sage

@Jessica28 

 

Please provide some more information on it,

On which table this email script has written

@Prince Arora 

I did not use any table in the email script.  Here is what I did and it works. I hope someone in the community can use it if there is a need

 

Jessica28_0-1697678814854.png

 

 

 

@Jessica28 

 

Email scripts are always invoked from the "Email Notification," and within the email notification, we need to select the relevant table.

So when we use the "current" keyword in the email script, it refers to the context of the table we've chosen in the notification.

To clarify, the original question didn't specify which table this email script was called for. so it was difficult to guide.

 

As you mentioned the above script works, that defines your email notification in on "sc_req_item" table as you are fetching the details from RITM.

 

Please mark it helpful if it has answer your query!