Email Templates and Emails
Email Templates
Links:
To create a link, click on the link icon and in the URL add the link without the instance.
e.g. /now/nav/ui/classic/params/target/pm_project.do%3Fsys_id=${sysapproval.sys_id}
For approvals it will act on the table: Approval (sysapproval_approver)
Use this type of syntax for getting variables when its to do with a Project:
${sysapproval} -> Gives the project number
Approval Sys ID: ${sys_id} -> Gives the Approval Sysid
${sysapproval.sys_class_name} -> e.g. "Project"
${URI} -> Takes you to the approval record
${sysapproval.URI} -> Link to the project
URL: sysapproval_approver.do?sys_id=${sys_id}
Project sysid: ${sysapproval.sys_id}
Subject: ${sysapproval.short_description}
Description: ${sysapproval.description}
Click here to view Approval Request: ${URI}
Click here to view ${sysapproval.sys_class_name}: ${sysapproval.URI}
Priority: ${sysapproval.priority}
Category: ${sysapproval.category}
Click here to Reject
Email Scripts:
To automatically approve: A Better, One-Click Approval - ServiceNow Developer Pro-Tips (snprotips.com)
Solved: Script Syntax for adding URL link in email script - ServiceNow Community
${mail_script:Notification: Feedback Task Resolved}
Tables:
sysevent_email_action.list -> Notifications
sys_email_layout.list -> The background layout
sysapproval_approver.list
sysevent_email_template.list
sys_script_email.list -> Email Scripts (See related link in the Notifications)
To explore:
Instance name: ${event.parm2}
${URI}
TAB: When to send
In the advanced condition:
answer = gs.getProperty('glide.knowman.enable_approval_notification','false');
%3D means =
Emails and Email Notifications
// This is a Notification Email Script. This example gets all tasks which are open
// or pending and were last updated 2 weeks ago. The Email was sent to ServiceDesk_CH
// weekly
// A "Scheduled Script Execution" triggers an "event" which triggers a Notification
// which is populated by this "Notification Email Script"
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// This function returns all the task which are with the Service Desk, are open or pending for at least 2 weeks
var noofdays = 14;
var x = -1;
var assto = '';
var str= '';
var taskGr = new GlideRecord('sc_task');
taskGr.addEncodedQuery("stateIN-5,1^assignment_group=5948b2abdbd513009a9867a3ca961903");
taskGr.query();
while (taskGr.next()) {
x++;
var currDate = new GlideDateTime();
var pastDate = new GlideDateTime(taskGr.sys_updated_on);
var dur = new GlideDuration();
dur = GlideDateTime.subtract(pastDate,currDate);
var days = dur.getDayPart();
if (days >= noofdays) {
var tklink = "/nav_to.do?uri=sc_task.do?sys_id=" + taskGr.sys_id;
var url = '<a href="' + tklink + '">' + taskGr.getValue('number') + '</a>';
if (!taskGr.assigned_to) {
assto = "Not assigned";
} else {
assto = taskGr.assigned_to.getDisplayValue();
}
str = x + " " + url + " Desc: " + taskGr.short_description + "<br>";
str = str + " State: " + taskGr.state.getDisplayValue();
str = str + " Assigned to: " + assto + " open:" + days + " days <br>";
template.print(str);
//template.print(x + " " + url + " Desc: " + taskGr.state.getDisplayValue() + " State: " + taskGr.state.getDisplayValue() + " Assigned to: " + assto + " open:" + days + ' days <br>');
}
}
})(current, template, email, email_action, event);
Email Notification using an Event
(Im sure that this a better way of doing this! But this is how I configured an Email that sent
sc_tasks which were open for more than 2 weeks in Sept 2024.)
See the "Tables" below next time to see if that helps with an alternative way and join them with this.
The Notification: sysevent_email_action
The Event Registry: sysevent_register
The Email script: sys_script_email
Scheduled Script Execution: sysauto_script
Error Handling
Error Handling:
Check the Email and at the bottom you might get a clue as to why the email didnt go out. e.g.
Notification 'Email ServiceDesk CH with open Tasks' (35e52ebfc3d45a909fde311a05013118) excluded recipients because system notification preference is inactive: 'Oliver Schulze' (ba070960db25bc10841e6d3405961970)
In this case Oliver has set this in his preferences.
A system Notification is an automated message sent by the platform.
Comments
Post a Comment