Guide to enable an on-call calendar schedule link for the assignment group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2024 11:48 AM
Streamlining On-Call Scheduling for Incident Management in ServiceNow
Use Case:
As an essential part of incident management in ServiceNow, efficiently handling on-call schedules can significantly improve response times and service quality. Recently, we received a requirement to enable an on-call calendar schedule link for the assignment group, ensuring that this link is visible only on the incident form and placed next to the assignment group field. This enhancement helps streamline access to on-call schedules, ensuring that the appropriate personnel are quickly identified and contacted during incidents.
In this article, I'll walk through the implementation process and provide an in-depth explanation of the code. I have modified the script which was available on Credits: ServiceNowGuru to achieve this functionality.
Prerequisites
Implementation Steps
- Creating the UI Macro:
- I created a UI Macro and added the dictionary attribute to the assignment_group ref_contributions=show_group_on_call_schedule.
- Added a dictionary override to the Task table to ensure this feature is not visible for all tasks, limiting it to incident records.
- Modified the dictionary attribute for the Incident table to enable the on-call icon.
The code should work without any changes:
<?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_schedule_${jvar_guid}:${ref}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}"
onclick="showOnCallSchedule('${jvar_n}')"
title="${gs.getMessage('Show group on-call schedule')}" image="images/icons/tasks.gifx" icon="icon-calendar"/>
<script>
// show oncall calendar
(function() {
function decorationShow(element, original, changed, loading) {
var $refButton = $j(gel('${jvar_n}'));
$refButton.attr('role', 'button');
}
var n = '${jvar_n}'.replace(/./g, '');
var h = new GlideEventHandler('onLoad' + n, decorationShow, '${ref}');
g_event_handlers.push(h);
})();
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>
Code Explanation
- Initialization:
- The Jelly script starts by generating a unique GUID using gs.generateGUID(this); and sets it as jvar_guid.
- The variable jvar_n is created to uniquely identify the on-call schedule link.
- Creating the Reference Decoration:
- The <g:reference_decoration> tag adds a clickable icon next to the assignment group field. This icon triggers the showOnCallSchedule function when clicked.
- The title and image attributes set the tooltip and icon image, respectively.
- Adding Event Handlers:
- The script defines a decorationShow function that sets the role of the reference button to "button".
- A new event handler is created and pushed to g_event_handlers to ensure the decoration is properly loaded when the form loads.
- Show On-Call Schedule Function:
- The showOnCallSchedule function retrieves the current assignment group.
- It queries the cmn_rota table to check if an active on-call rotation exists for the group.
- If an active rotation is found, a URL is constructed to display the schedule in a popup window.
- If no active rotation is found, an alert notifies the user.
Conclusion
By implementing this feature, I was able to provide a quick and efficient way for incident responders to access on-call schedules directly from the incident form. This enhancement reduces response times and ensures that the appropriate personnel are readily available to handle incidents.
If you believe the solution provided has adequately addressed your query, could you please **mark it as 'Helpful'** and **'Accept it as a Solution'**? This will help other community members who might have the same question find the answer more easily.
Thank you for your consideration.
Selva Arun