Send a Mention Email Notification for Incident Records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 03:31 PM
Hello,
I want to create a email notification for when a user gets mentioned in a Incident form. I tried using the live_notification but it doesn't incident numbers and will show up as blank when previewing notifications.
I've tried using the incident table but when I go to select users/groups the option for User[sys_users] is not available.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 08:54 PM
Hi, I am not sure that you need to do anything as the OOB @ mentions notification seems to work correctly without modification - at least it includes the Incident number in my PDI testing, which was your original requirement.
So perhaps start by checking your notification is configured as it is OOB, and that noone has modified the notification email script hat it depends on.
If you need to make changes I would start by reviewing the SNC documentation covering notifications and notification email scripts.
Notifications (servicenow.com)
Scripting for email notifications (servicenow.com)
Then the developer site has a basic learning module for notifications which will help
Automating Application Logic | ServiceNow Developers
Then
Copy the OOB notification email script indicated in above post, modify it to meet your requirements IE so it will populate the content you require into your notification.
Then copy the OOB @ mentions notification, modifying it to reference your 'new' notification email script, test using preview and a suitable event, modify\update your script until happy with results.
Disable the OOB @ mentions notification.
Move these updates from dev\test to production.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 09:09 PM
Thank you for your resources, I greatly appreciate it. I checked and the email script is OOB and has not been configured.
Is it possible for it to be the table values? Because when I use ${URI} it doesn't take me directly to the incident. Instead it takes me to the live_notification table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 09:26 PM
${URI} is a reference to the current record (record that triggered the notification), which as you discovered is the live_notification record not the Incident.
The OOB notification email script 'ng_activity_mention_body' already includes a URL link to the triggering task (at least my PDI version does), and your requirements are not clear from your posts.
If you want to return values from the incident table then you will need to map these in your notification email script.
Looking at the OOB solution it provides limited data from the triggering record via this method ActivityMentionEmailValues()
If you requirement than the OOB configuration you would normally run a QlideQuery against your incident so that you can map content directly.
GlideRecord | ServiceNow Developers
var recCheck = new GlideRecord(current.table)
if(recCheck.get( current.document) {
//if a valid record exists then you have your incident as an object and can dot.walkt to any field.
gs.info('task number ' + recCheck.number;
}
If you provided clear and specific details of your requirements and your configuration, it would be easier to understand your issue and to and help you find a solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 09:54 PM
My apologizes,
The issue is whenever a user is mentioned in the activity stream it does not trigger an email notification to let the user be aware. This has happened a lot with the incident records, when I went to check the notification email template it was assigned to the incident table, and I changed it to live_notification table and made sure to add users as "who will receive." However, when I took a look at the preview I saw the Incident{$number} in the email body was blank. That is when I changed it to {$URI} and I looked at the preview again, clicked on the link and it takes me somewhere different.
I need help getting the Incident ${number} to appear and direct it to the incident record when you click on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 10:02 PM
HI @SParker12 ,
I trust you are doing great.
- Create a new Business Rule in ServiceNow that triggers when a user is mentioned in the Incident form.
- In the Business Rule script, write code to retrieve the mentioned user and their email address.
- Use the retrieved information to construct an email notification.
- Send the email notification to the mentioned user.
Here's an example of how you can implement this solution:
Step 1: Create a Business Rule
- Navigate to "Business Rules" in ServiceNow.
- Click on "New" to create a new Business Rule.
- Provide a name and description for the Business Rule.
- Set the "When to run" field to "After" and choose the appropriate condition for when a user is mentioned in the Incident form.
- Save the Business Rule.
Step 2: Retrieve User Information
- In the Business Rule script, use GlideRecord to query the Incident table and retrieve the mentioned user's information.
- Here's an example code snippet:
(function executeRule(current, previous) {
var mentionedUserId = current.mentioned_user; // Assuming the mentioned user is stored in a field called 'mentioned_user'
var userGR = new GlideRecord('sys_user');
if (userGR.get(mentionedUserId)) {
var mentionedUserName = userGR.name;
var mentionedUserEmail = userGR.email;
// Use the retrieved user information to construct the email notification
// (code for email construction not provided here)
// Send the email notification to the mentioned user
// (code for sending email not provided here)
}
})(current, previous);
Step 3: Construct Email Notification
- Use the retrieved user information (mentionedUserName and mentionedUserEmail) to construct an email notification.
- This involves creating an HTML or plain text email template with the desired content, including the mentioned user's name, incident details, etc.
- Use ServiceNow's email API or a similar method to send the email. The code for sending emails will depend on your specific email integration setup.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi