Skip to content

Send notification to the assigned user #1117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions UI Actions/Send notification to the assigned user/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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.

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.
When the button on the incident form is clicked, an email notification will be sent to the user to whom the incident is assigned.

-> If the incident is not assigned to any user, a message will be shown, and no email will be sent.
-> If the assigned user's email address is missing, the email will not be sent, and an appropriate message will be displayed.
-> 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.
26 changes: 26 additions & 0 deletions UI Actions/Send notification to the assigned user/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//Servver Side Script to send notification to the assigned to user
var assignedToEmail = current.getValue('assigned_to'); // Fetches the sys_id of the assigned_to field
if (assignedToEmail) {
var userGR = new GlideRecord('sys_user'); // Access the sys_user table
var txt_email = "";
if (userGR.get(assignedToEmail)) {
txt_email = userGR.getValue('email'); // Retrieves the email field from the sys_user record
}
if (txt_email) {
var gr_sys_email = new GlideRecord('sys_email');
gr_sys_email.initialize();
gr_sys_email.setValue('type', 'send-ready');
gr_sys_email.setValue('subject', 'UI Action Notification from Incident ' + current.number);
gr_sys_email.setValue('recipients', txt_email);
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.');
gr_sys_email.insert();
}
else
{
gs.addInfoMessage("The email address for the user " + userGR.getValue('name') + " is missing. As a result, the email could not be sent.");
}
}
else
{
gs.addInfoMessage("The incident " + current.number + " has not been assigned to any user. Therefore, the email could not be sent.");
}
Loading