Screen PopUp from Workflow

Andrew Bettcher
Kilo Sage

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?

 

1 ACCEPTED SOLUTION

Andrew Bettcher
Kilo Sage

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.

View solution in original post

9 REPLIES 9

Andrew Bettcher
Kilo Sage

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.

Hi Andrew,

 

Can we configure it only for tasks under current logged in users group?

 

Thanks,

Lavanya

Hello,

I think you could. You need to get the logged in users group and amend this line:

gr.user_filter = 'sla_message';

I'm sorry but I don't have time to work on this now to see how it would work but might be able to over the next few weeks.

The only issues I can think of is that users can belong to multiple groups so I think you'd need to pull all of the current users groups back into an array and then compare them to the ones you want to receive the message. If it finds a match show message, if not, do nothing.

Good luck and, if you manage to sort this out could you post your solution here for other users please?

Hi Andrew,

Thanks for the reply. Instead of current logged in users all groups, can we specify this broadcast message only to a certain group users without this below role?

'sla_message'

 

Thanks,

Lavanya

Hi,

This is just a guess but I think you'd need to add a new field to the broadcast message form to take the group that you want to receive the message and then find the script include that runs the broadcast messages

(MegaphoneBroadcast: yourinstance/nav_to.do?uri=%2Fsys_script_include.do%3Fsys_id%3D7c000f2147200200151119fbac9a716c%26sysparm_record_target%3Dsys_script_include%26sysparm_record_row%3D2%26sysparm_record_rows%3D2%26sysparm_record_list%3DnameCONTAINSbroadcast%5EORDERBYDESCsys_updated_on).

Line 36 (out of the box) tells it to find the role specified on the broadcast form so you could change that to look for the group instead.

However, it would be much simpler to create a new role and assign that role to the group or groups that you want to broadcast to.