Skip to content

Commit 6013cba

Browse files
authored
Send notification to the assigned user (#1162)
* Create script.js UI Action Server Side Script to send notification to the assigned user * Create readme.md Readme - UI Action Server Side Script to send notification to the assigned user * Update readme.md Updates a note for users in readme file
1 parent c0c1c12 commit 6013cba

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Please note - Users should endeavor to use Flow, Notifications, etc., but UI Action option is also available.
2+
-------------------------------------------------------------------------------------------------------------------------------------------
3+
A UI Action in ServiceNow is a script that defines an action or button within the platform's user interface. It enables users to perform specific operations on forms and lists, such as creating, updating, or deleting records, or executing custom scripts. UI Actions enhance the user experience by providing functional buttons, links, or context menus.
4+
5+
In this case, the UI Action contains a server-side script that creates a record in the sys_email table, including the email body, subject, and recipient details.
6+
When the button on the incident form is clicked, an email notification will be sent to the user to whom the incident is assigned.
7+
8+
-> If the incident is not assigned to any user, a message will be shown, and no email will be sent.
9+
-> If the assigned user's email address is missing, the email will not be sent, and an appropriate message will be displayed.
10+
-> However, if the incident is assigned to a user with a valid email address, the UI Action will successfully send the email to the assigned user.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Servver Side Script to send notification to the assigned to user
2+
var assignedToEmail = current.getValue('assigned_to'); // Fetches the sys_id of the assigned_to field
3+
if (assignedToEmail) {
4+
var userGR = new GlideRecord('sys_user'); // Access the sys_user table
5+
var txt_email = "";
6+
if (userGR.get(assignedToEmail)) {
7+
txt_email = userGR.getValue('email'); // Retrieves the email field from the sys_user record
8+
}
9+
if (txt_email) {
10+
var gr_sys_email = new GlideRecord('sys_email');
11+
gr_sys_email.initialize();
12+
gr_sys_email.setValue('type', 'send-ready');
13+
gr_sys_email.setValue('subject', 'UI Action Notification from Incident ' + current.number);
14+
gr_sys_email.setValue('recipients', txt_email);
15+
gr_sys_email.setValue('body', 'As the incident ' + current.number + ' is assigned to you, this UI Action Notification has been sent. Please review the incident.');
16+
gr_sys_email.insert();
17+
}
18+
else
19+
{
20+
gs.addInfoMessage("The email address for the user " + userGR.getValue('name') + " is missing. As a result, the email could not be sent.");
21+
}
22+
}
23+
else
24+
{
25+
gs.addInfoMessage("The incident " + current.number + " has not been assigned to any user. Therefore, the email could not be sent.");
26+
}

0 commit comments

Comments
 (0)