
- 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,474 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 08:39 AM
Where are you running the above script? I can see you using current.incident.number. Is incident a valid field in the current record?
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 08:54 AM
Hello Palanikumar!!
The script is running against a custom table that extends from the incident table, where there are two incident forms (Table Name: "u_operational_mechanical_incident) ... The number field is the OOTB number field on the incident forms.
My thought process was that by adding the full URL to direct to the incident number into the script, it would display the incident number - instead it displays "undefined" but when you click the undefined link it opens to the correct incident that needs approval.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 12:04 PM
Any other thoughts on this??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 12:26 PM
//Try. untested
var date = gs.nowDateTime();
var end = gs.minutesAgo(15);
var inc_link = createLinkForObject(current.getTableName(),current.sys_id, current.number);
function createLinkForObject(strTableName, strSysID, number){
return '<a class="web" href="' + gs.getProperty('glide.servlet.uri') + gs.generateURL(strTableName, strSysID) + '" target="_blank">' + number + '</a>';
}
var gr = new GlideRecord('sys_broadcast_message');
gr.initialize();
gr.message = 'Incident ' + inc_link + ' 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();
Vinod Kumar Kachineni
Community Rising Star 2022