- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2025 09:12 AM
There are existing two email notification on the sc_task and SLA Table
1. sc task mail subject : Task ${number} has been assigned to your group
2. sla task subject : SLA "{sla}" associated with {task.number} has breached
These are two existing mail subjects, Now for this subject I need to Write an email script to dynamically populate subject with customer name along with task number if the catalog type is SSR/CSR. For others, it should remain as is,
to find the catalog item type we have an field in the ScTask called item which is highlighted in green color, If I click on the item , it will be re-directed to sc_cat-item, here we have an catalog type field,
And for the customer name, in the ritm we have an account variable that should be pulled.
Can anybody help me with the script for both of the table SLA & Sc_task And how to call the mail script dynamically. in the subject, if the catalog is SSR or CSR then should subject should contain customer name.
Thanks,
Looking forward for the solution
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2025 10:45 PM
you can set the email subject using email script like this
Also include the email script like this, remove subject from email notification as it will be set via the email script now
${mail_script:mailScriptName}
1) email script for notification on sc_task
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var task = current;
var item = task.item.getRefRecord();
var catalogType = item.u_catalog_type; // Assuming 'u_catalog_type' is the field name for catalog type
var customerName = task.variables.account; // Assuming 'account' is the variable name for customer name
if (catalogType == 'SSR' || catalogType == 'CSR') {
email.subject = 'Task ' + task.number + ' has been assigned to your group - ' + customerName;
} else {
email.subject = 'Task ' + task.number + ' has been assigned to your group';
}
})(current, template, email, email_action, event);
2) email script for notification on task_sla
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var slaTask = current.task.getRefRecord();
var item = slaTask.item.getRefRecord();
var catalogType = item.u_catalog_type; // Assuming 'u_catalog_type' is the field name for catalog type
var customerName = slaTask.variables.account; // Assuming 'account' is the variable name for customer name
if (catalogType == 'SSR' || catalogType == 'CSR') {
email.subject = 'SLA "' + current.sla + '" associated with ' + slaTask.number + ' has breached - ' + customerName;
} else {
email.subject = 'SLA "' + current.sla + '" associated with ' + slaTask.number + ' has breached';
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2025 10:45 PM
you can set the email subject using email script like this
Also include the email script like this, remove subject from email notification as it will be set via the email script now
${mail_script:mailScriptName}
1) email script for notification on sc_task
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var task = current;
var item = task.item.getRefRecord();
var catalogType = item.u_catalog_type; // Assuming 'u_catalog_type' is the field name for catalog type
var customerName = task.variables.account; // Assuming 'account' is the variable name for customer name
if (catalogType == 'SSR' || catalogType == 'CSR') {
email.subject = 'Task ' + task.number + ' has been assigned to your group - ' + customerName;
} else {
email.subject = 'Task ' + task.number + ' has been assigned to your group';
}
})(current, template, email, email_action, event);
2) email script for notification on task_sla
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var slaTask = current.task.getRefRecord();
var item = slaTask.item.getRefRecord();
var catalogType = item.u_catalog_type; // Assuming 'u_catalog_type' is the field name for catalog type
var customerName = slaTask.variables.account; // Assuming 'account' is the variable name for customer name
if (catalogType == 'SSR' || catalogType == 'CSR') {
email.subject = 'SLA "' + current.sla + '" associated with ' + slaTask.number + ' has breached - ' + customerName;
} else {
email.subject = 'SLA "' + current.sla + '" associated with ' + slaTask.number + ' has breached';
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader