H
ere’s a UI macro that I’ve used for a couple of clients that allows you to pop open an on-call rotation schedule for the group selected in any ‘Group’ reference field in the system. This will probably be most useful for the ‘Assignment group’ table that you use on the task table. As with any reference field UI macro, you can add the UI macro to your reference field by adding the ‘ref_contributions’ attribute to the dictionary entry of your reference field. So this macro would require the ‘ref_contributions=show_group_on_call_schedule’ attribute. Since it displays on-call information, it is also dependent on the ‘on_call scheduling’ plugin being installed.
Here’s the code you’ll need for your UI macro. This code should work without modification for any group reference field in your system.
Name: show_group_on_call_schedule
Description: Displays an on-call schedule for the selected assignment group.
Requires ‘ref_contributions=show_group_on_call_schedule’ dictionary attribute.
XML:
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="show_on_call_${jvar_guid}:${ref}"/>
<span id="${jvar_n}" onclick="showOnCallSchedule('${ref}')" title="${gs.getMessage('Show group on-call schedule')}" alt="${gs.getMessage('Show group on-call schedule')}" tabindex="0" class="btn btn-default icon-date-time">
<span class="sr-only">${gs.getMessage('Show group on-call schedule')}</span>
</span>
<script>
function showOnCallSchedule(reference){
//Get the current group
var group = g_form.getValue(reference.split('.')[1]);
//Query to see if an on-Call rotation exists
var grpRota = new GlideRecord('cmn_rota');
grpRota.addQuery('group', group);
grpRota.addQuery('active', true);
grpRota.query();
if(grpRota.hasNext()){
//Construct a URL for the popup window
var url = 'show_schedule.do?sysparm_type=roster$[AMP]sysparm_zoom=weekly$[AMP]sysparm_group_id=' + group;
//Open the popup
popupOpenStandard(url);
}
else{
alert('No active rotation specified for the selected group.');
}
}
</script>
</j:jelly>
This is nice. It definitely saves our Help Desk time when needing to locate an on-call name…
Thanks once again for a cool trick.
Which dictionary entry did you add the attribute to? cmn_schedule?
The dictionary attribute needs to be added to the reference field that you want to see the icon next to. For this example, the dictionary attribute gets added to the ‘Assignment group’ field.
If you have rotas that are not active (cmn_rota.active = false) then the pop-up window will display with the first group rota in the cmn_rota table. If you are not paying attention then you may be trying to contact the on-call person in the wrong group.
This is easily fixed by adding a query statement to test for an active rota. Added the following below the query for group.
grpRota.addQuery(‘active’, true);
This now displays the proper message that no rotation is specified. I guess the message could be adjusted to state that no active rotation is specified.
Good catch. I’ve updated the post to reflect these changes.
Is it possible to do something similar for the Rotation Schedule Report so the phone numbers are visible?
I’m sure it’s possible, but a bit more challenging because that report asks for date ranges as well. I don’t have anything currently that does that but I’ll be sure to post here if I come up with anything.
We’re not using any of the automatic functionality. We just need to know who is on call at that moment so the date range would just be ‘now’. The Rotation Schedule Report includes the phone numbers for the on-call person for the Assigned Group and a link to our paging software. It would be convenient to be able to click on the icon for immediate information.
Is there a way to get the first box on the schedule (the one that says the name of the schedule. In your example the Off Hours Workday box) so that the person name and contact info will be the only box listed in that field?
I don’t know the answer to that off the top of my head, but if it is possible it would be part of the schedule properties. My guess is that it can’t be done.
Hi Mark,
Just wondering if there is a way to show the reference_decoration popup via ‘onHover’ or ‘onMouseOver’ display, instead of the ‘onclick’ event.
I know this is not native to XML, but ServiceNow uses the hover_icon.gifx on many fields to generate popups on mouseover.
Thanks,
I looked into that once, but couldn’t figure it out. I’m sure there’s a way, but I don’t know how it’s done yet.
I too would like to utilize the ‘onMouoseOver’ display…
It’s been a while – any chance you found a way to make ref_contribution load on mouse over?
Sorry Eric, I haven’t found a way to do that yet.
Any idea if this could be made to work in Fuji’s On-Call Scheduling?
It works just fine with on-call scheduling as well. I just updated the macro above to use the new Fuji styling for the icon. Should work without issue.
Hi Mark,
I applied this to our Eureka instance and rather than the clickable icon, it says “Show group on-call schudule” to the right of the Assignment Group field. It still works, when you click the words, it brings up the on-call schedule, but doesn’t look as nice. I applied this to a Fuji development site I spun up and it works perfectly. Is it beause we are on Eureka?
Thanks,
Yes, the code above has been updated to be compatible with instances from Fuji onward. One thing you’ll notice when you upgrade from Eureka is that most of your UI macro icons will be messed up. You’ll need to adjust them all so that the icon appears in a span like I have in my code above. If you want this to look right in your Eureka instance, you’ll need to find a UI macro in your system and adjust the line with ‘btn-default’ to point to an ‘img src’ tag instead.
That worked. Thanks.
Wow that was easy and very helpful. Thanks for putting this out there.