Setting email subject with a mail script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2011 08:57 AM
I have a field that I need to set in a subject line of an email. The email is coming from the "request" table, and the field is on the "sc_cat_item" table. I have a mail script within the email body, but I need to set the field in the subject. How can I achieve this? This is the mailscipt I'm using in the body:
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while(gr.next()) {
template.print(gr.variables.requested_for23 + ": + "\n");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2011 01:38 PM
Hi Blair,
You can set the subject in the mail_script like the example below:
<mail_script>
var str = 'This is my subject ' + current.cat_item.FIELD;
email.setSubject(str);
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while(gr.next()) {
template.print(gr.variables.requested_for23 + ": + "\n");
}
</mail_script>
Or you should just be able to use the email syntax in the subject line as well to pull that field over
This is my subject ${cat_item.FIELD}
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2011 05:36 AM
None of the above worked for me. After messing with it for about an hour, I finally got it to work like this. My needs were as follows. On my termination workflow, I needed a special email to go to HR telling them that the termination was complete. The wanted the persons name in the Subject of the email. I already had a Notification piece in my workfow that was sending them an email. I inserted the following line in the mail script. The variable on my catalog was called employee_name I wanated it to look like this
Employee Termination: (John Doe) has been COMPLETED
email.subject = "Employee Termination: " + "(" + current.variable_pool.employee_name + ")" + "has been COMPLETED" ;
Here is the rest of the notification with the inserted line. This is all in the Message portion of the notification.
Click here to view request: ${URI_REF}
Number: ${number}
Due date: ${due_date}
Opened: ${opened_at}
Approval: ${approval}
email.subject = "Employee Termination: " + "(" + current.variable_pool.employee_name + ")" + " has been COMPLETED" ;
template.print("Employee name - " + current.variables.employee_name + "\n");
template.print("Employee Department - " + current.variables.employee_dept.name + "\n");
template.print("Requestor Location - " + current.variables.location.name + "\n");
template.print("Employee Position - " + current.variables.employee_position + "\n");
template.print("Employee Number - " + current.variables.employee_number + "\n");
template.print("Supervisor - " + current.variables.supervisor_name.name + "\n");
template.print("Due Date - " + current.variables.term_date + "\n");