
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 07:43 AM
Hi,
We have a workflow on the task_sla table that waits for 50% of the SLA and then sends a notification email. I think there is an OOTB workflow that does this but we have created our own as some elements were corrupted somewhere along the line (prior to me joining the company).
We want to make a pop-up box appear to all users in a certain group when an SLA breaches. This would have to appear regardless of where they are in the system at the time of the breach. We don't anticipate a large number of breaches and the team that will see the pop-up are all Service Desk operatives and so would required to take some kind of action to prevent the breach (at the moment they get an email but we're still seeing unnecessary breaches).
I ahve added a "Run Script" node which comes off the same node as the email notifications node. The script in this node is simply:
var pop = new BreachPopUp();
pop.pop();
which is supposed to call my Script Include function BreachPopUp.pop.
I think it does because I added a copy of this onto the start node and the script include has a gs.addInfoMessage on there which did appear when it was supposed to.
So, I think I am calling the script include correctly.
After watching Chuck and Andy's TechNow Episode 6 on Script Includes and wrote this:
var BreachPopUp =Class.create();
BreachPopUp.prototype={
initialize :function(){},
pop :function(){
gs.addInfoMessage("SLA Has Breached");
},
type :'BreachPopUp'};
I'm sure you've all guess that this doesn't work although something does happen when the 50% point is reached. It appears as though the ticket is refreshing itself at this point but only if I am looking at the ticket in question. If I am anywhere else in the instance nothing happens.
I've seen 40 or 50 posts on similat things but nothing exactly like this and so I don't even know if this is possible. I started off looking at events and then calling the script that way but that seems pointless when the event is already defined in the workflow.
Will this always fail because I'm trying to do something on the client based on something that is happening on the server or is the right way to mix the two?
Am I on the right track but with bad script or do I need to rethink (or do I need to tell my customers that it's not possible)?
If it isn't possible, is there another way to get an instant message to a user?
Solved! Go to Solution.
- 2,579 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2019 04:38 AM
OK Pop Pickers. Hold on toy our hats....
To summarise the entire solution:
1. Created new role called sla_message and added this to the Service Desk group
2. Created new SLA workflow that waits 50%, 25% and 25% of the overall SLA time before running scripts
3. Created the below workflow script in Run Script workflow nodes:
var gr = new GlideRecord('sys_broadcast_message');
var date = gs.nowDateTime();
var end = gs.hoursAgo(-1);
var task = current.task.number;
var sysID = current.task.sys_id;
var url = 'https://mtidev.service-now.com/task.do?sys_id='+ sysID;
var urlString = '<a class="web" target="_blank" href = "'+ url + '">' +task + '</a>';
gr.initialize();
gr.message = 'Incident ' + urlString + ' has reached 50% of its SLA';
gr.user_filter = 'sla_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();
4. Associate the new workflow with relevant SLAs
5. Bob's your uncle.
The script inserts a new entry onto the sys_broadcast_message table set to only exist between "now" and "now +1 hour". The message shows the task ID which is displayed as a link in a red banner at the top of the screen.
It appears on a users screen whenever they take any action in any area of ServiceNow so if they were working on changes and, for example, added a new note to a change and saved the record, the notification would appear.
Clicking the link will open a new tab showing the target incident.
The bits after the "gr.initialise(); line just tell the script what to put into the broadcast message fields. You can make it so that it notifies new users as they log in or sends an email instead of displaying the message. You can also vary the lenght of time the message appears for by changing the number of negative hours in the "end" variable.
If preferred, change the "_blank" to "_self" or "_new" to change the behaviour of the link. _self causes it to open in the current tab. _new opens an entirely new window.
Each broadcast message tracks the people that have had the specific popup and so, once the move onto a different page or clear the message down it won't appear again for the same user.
I vow to annotate the script before I consider this task complete. 😉
Happy to help out if you want to try it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 07:45 AM
Sorry. In script above, whjere it says "addInfoMessage" it should read "confirm"
i.e.
var BreachPopUp =Class.create();
BreachPopUp.prototype={
initialize :function(){},
pop :function(){
gs.confirm("SLA Has Breached");
},
type :'BreachPopUp'};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 07:55 AM
One of the trickiest thing is to initiate a client side popup from Server side event, what I can suggest to create an EVENT which will fire gs.addInfoMessage() , based on that you may be able to trigger client side ALERT or CONFIRM message ( not tried, just a theory based on http://sncommander.com/
If not, please see above link helps you
Note: Please mark reply as correct / helpful if it answers your question

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2019 02:03 AM
Good Morning Pop Pickers,
I have something like a solution that just needs a bit of work to get it working. I came across a post about sys_broadcast_message. I did some tests and it notified my test users in our DEV system.
I have a "Run Workflow" node in the SLA breach notification workflow that creates a new record in the broadcat table and sets the start time and end time's accordingly.
To avoid spamming all users I created a new role called sla_message and added it to the Service Desk group.
The theory works and the workflow is running the script and creating a new broadcast record but I can't get it to bring back todays date AND time.
Here's my current script:
var gr = new GlideRecord('sys_broadcast_message');
var date = new GlideDateTime(gs.nowDateTime());
var end = new GlideDateTime(gs.nowDateTime());
end.addSeconds(3600);
gr.initialize();
gr.message = 'Incident has reached 50% of its SLA';
gr.user_filter = 'sla_message';
gr.at_login = 'false';
gr.logged_in = 'true';
gr.notify_users_after_date = date;
gr.notify_users_until_date = end;
gr.insert();
It puts today's date in but the time given is 00:00:00 rather than "now". The "end" var is today at 01:00:00.
D'oh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2019 02:00 AM
Hi,
We solved this thanks to a post by Chuck T about using negative amounts of "hoursAgo".
The script is:
var gr = new GlideRecord('sys_broadcast_message');
var date = gs.nowDateTime();
var end = gs.hoursAgo(-1);
var sla = current.sys_id;
gr.initialize();
//gr.message = ('Incident' + task + ' has reached 50% of its SLA');
gr.message = sla;
gr.user_filter = 'sla_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();
We want to put the breached task ID into the message whihs is why I've called the sys_id although this is the sys_id of the broadcast message rather than the task_sla. I'll work out how to get the task ID and then post it here.