Notifications - User Story 02
Title : Send Notification Email Upon Ticket Update
Description:
As a user of the IT Service Desk system, I want to receive a notification email whenever a ticket is updated so that I am informed about any changes made to the ticket assigned to me.
Acceptance Criteria:
When a ticket is updated, an email notification should be sent to the assigned user, the requester, and the members of the additional POCs.
The subject of the email should follow the format: "Ticket [Ticket Number] - Updated".
The body of the email should contain the following information:
To: Assigned to User,
CC: Requester, Additional POCs
Subject: Ticket: [Ticket Number] - Updated
Body:
Hi [Assigned to] / All,
The following ticket has been updated. Please review the details: [Ticket Number as Link]
Ticket: [Ticket Number]
Short Description: [Short Description]
Created on: [Created Date]
Created by: [Creator]
Please check the [Link] for more details.
Thanks,
IT Support
Devlopment Plan:
Create one Notification on target table.
Create Email Script to add Email IDs in CC.
Add Email Script to the Notification newly created.
Devlopment Steps:
Go to Table list where you need to create Notification. Here, i am using my newly created table: "IT Service Desks".
Open any record > Right click on form banner > go to Configure > Notifications.
Click New, and provide the below details in Notification form to create new Notification.
Name : Notification on Ticket Update
Table : IT Service Desk // Provide your table name here
When to Send:
Send when : Record inserted or updated.
Updated : True
Who will receive:
Users/Groups in fields : Assigned to, <Here, select required fields from field list>
What it will contain:
Subject : Ticket ${number} - Updated <Here, replace 'number' with your field name.>
Message HTML : <Here, provide the below details, and replace field names with your table field names.>
Hi ${assigned_to} / All,
The following ticket has been updated. Please review the details: ${REF}
Ticket: ${number}
Short Description: ${short_description}
Created on: ${sys_created_on}
Created by: ${u_requester}
Please check the ${URI} for more details.
Thanks,
IT Support
${mail_script:ScriptName}
To add CC : To add email address list in mail CC, here in above Message HTML field, along with mail body, at the end of mail body, we need to add a line to call Email Script. This Email Script will help to add mail IDs list to mail CC while sending mail notification. Follow "Steps to create Email Script" from the below. (ex: ${mail_script: Add_Email_IDs_in_CC} ).
Click on Save (Right click on form banner, then click on Save option to save the Notification).
Steps to create Email Script:
Navigate to All ==> System Notification ==> Email ==> Notification Email Scripts
Click New, and provide the below details in form to create new Email Script.
Name : Add_Email_IDs_in_CC
Script : <Place the below script in script section>
// Add the email address and display name of the user who submitted the issue to the "cc" field
email.addAddress("cc", current.u_issue_submitted_by.email, current.u_issue_submitted_by.user_name);
// Check if Additional POC's are provided
if (!current.u_additional_pocs.nil()) {
// Create a GlideRecord object to query the sys_user table
var user = new GlideRecord('sys_user');
// Add a query condition to filter user records by Additional POCs sys_id
user.addQuery('sys_id', 'IN', current.u_additional_pocs);
// Add a query condition to filter out user records without an email address
user.addQuery('email', '!=', '');
// Execute the query
user.query();
// Iterate over each user record that matches the query conditions
while (user.next()) {
// Add the email address and display name of each user to the "cc" field
email.addAddress('cc', user.email, user.getDisplayValue());
}
}
Here in above script, Update the field names u_issue_submitted_by and u_additional_pocs with your table field names.
Click Save. Now Email script is created and ready to use in Notifications.
Update the 'Message HTML' field under 'What it will contain' section in Notification newly created above with email script information. Ex: ${mail_script: Add_Email_IDs_in_CC}
Click on Save (Right click on form banner, then click on Save option to save the Notification).
Click on "Preview Notification" Button to see the preview of notification which we created now with above steps.
Step by step screenshots: