
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 08:14 AM
I have a requirement to create a popup message to logged in users of a group when a communication approval is needed on an incident - rather than an email approval request. To achieve this I created a new role (approval_message) and assigned it to the group and then wrote a workflow script that adds a record to the sys_broadcast_message table with each of the fields set as well as the length of time that the message should run. Next, I added to the flow for this incident type. It works perfectly in terms of the display message, except that I noticed:
1. On the popup message the incident number does not show. It shows "undefined" instead but when you click on the link it takes you to the correct incident number that needs approval.
2. The message should only pop up for 15 mins. but when I check the sys_broadcast_table entry, the timing is off by hours and the *Notify users until date is set for many many hours later. Can someone please tell me what I'm doing wrong in my script?
Script:
var gr = new GlideRecord('sys_broadcast_message');
var date = gs.nowDateTime();
var end = gs.minutesAgo(15);
var incident = current.incident.number;
var sysID = current.sys_id;
var url = 'https://onedev.service-now.com/u_operational_mechanical_incident.do?sys_id='+ sysID;
var urlString = '<a class="web" target="_blank" href = "'+ url + '">' +incident + '</a>';
gr.initialize();
gr.message = 'Incident ' + urlString + ' has been submitted for a communication approval. Please refer to the My Approvals link to review the details of this incident and either approve or reject the approval';
gr.user_filter = 'approval_message';
gr.at_login= 'false';
gr.logged_in = 'true';
gr.email = 'false';
gr.notify_users_after_date = date;
gr.notify_users_until_date = end;
gr.insert();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- 1,476 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 02:06 PM
var start = new GlideDateTime();
var end = new GlideDateTime();
end.addSeconds(900); //15 minutes is 900 secs.
//These are true/false fields. please adjust as below.
gr.at_login= false;
gr.logged_in = true;
gr.email = false;
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 01:53 PM
Thank you so much Vkachineni!!! That actually worked perfectly for the incident link but the timing is still set out for 5 hours rather than 15 minutes.
The line in the script to account for the *Notify users until date* is line 2:
var end = gs.minutesAgo(15);
Can you please help me to modify this so that it only sets the until date out for 15 minutes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 02:06 PM
var start = new GlideDateTime();
var end = new GlideDateTime();
end.addSeconds(900); //15 minutes is 900 secs.
//These are true/false fields. please adjust as below.
gr.at_login= false;
gr.logged_in = true;
gr.email = false;
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 03:15 PM
Thank you so much!!! This worked perfectly!! I really appreciate your help ... THANK YOU!!!