On-call Schedule Popup UI Macro

///On-call Schedule Popup UI Macro

On-call Schedule Popup UI Macro

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.

SNOnCallSchedule

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.

‘show_group_on_call_schedule’ UI Macro
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:

<?xml version="1.0" encoding="utf-8" ?>
<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>
By | 2018-07-09T15:00:00-06:00 May 9th, 2011|Categories: UI macros|Tags: , , |21 Comments

About the Author:

21 Comments

  1. Jason Stephens May 11, 2011 at 1:47 am - Reply

    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.

  2. Matt June 9, 2011 at 2:26 am - Reply

    Which dictionary entry did you add the attribute to? cmn_schedule?

    • Mark Stanger June 9, 2011 at 2:35 am - Reply

      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.

  3. David Pesek July 20, 2011 at 11:32 am - Reply

    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.

    • Mark Stanger July 20, 2011 at 11:35 am - Reply

      Good catch. I’ve updated the post to reflect these changes.

  4. Rose October 5, 2012 at 11:37 am - Reply

    Is it possible to do something similar for the Rotation Schedule Report so the phone numbers are visible?

    • Mark Stanger October 5, 2012 at 5:24 pm - Reply

      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.

      • Rose October 8, 2012 at 7:00 am - Reply

        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.

  5. Allison December 7, 2012 at 8:03 am - Reply

    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?

    • Mark Stanger December 7, 2012 at 1:17 pm - Reply

      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.

  6. Taco Dols March 21, 2013 at 9:04 am - Reply

    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,

    • Mark Stanger March 21, 2013 at 9:06 am - Reply

      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.

  7. Chris McDevitt September 7, 2013 at 5:48 pm - Reply

    I too would like to utilize the ‘onMouoseOver’ display…

  8. Eric January 16, 2015 at 2:02 pm - Reply

    It’s been a while – any chance you found a way to make ref_contribution load on mouse over?

    • Mark Stanger January 21, 2015 at 9:35 am - Reply

      Sorry Eric, I haven’t found a way to do that yet.

  9. Jim Marchant September 25, 2015 at 5:21 pm - Reply

    Any idea if this could be made to work in Fuji’s On-Call Scheduling?

    • Mark Stanger September 28, 2015 at 7:52 am - Reply

      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.

  10. Chris March 24, 2016 at 1:23 pm - Reply

    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,

    • Mark Stanger March 24, 2016 at 2:47 pm - Reply

      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.

      • Chris March 31, 2016 at 12:42 pm - Reply

        That worked. Thanks.

  11. Jason McGrath October 26, 2017 at 2:23 pm - Reply

    Wow that was easy and very helpful. Thanks for putting this out there.

Leave A Comment