Help with script to display broadcast message based on role

Nya Valdez1
Tera Contributor

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. 

find_real_file.png

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?

find_real_file.png

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();
1 ACCEPTED SOLUTION

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;

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

7 REPLIES 7

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.

find_real_file.png

 

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?

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;

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Thank you so much!!! This worked perfectly!! I really appreciate your help ... THANK YOU!!!