Enhancing ServiceNow’s Delegate Feature: Out of Office

ServiceNow’s delegate feature is a powerful tool that allows users to specify colleagues who can handle their work during absences. This feature ensures continuity in task management and notification handling. For a comprehensive guide on delegates in ServiceNow, you can refer to this community article.

To further improve the delegate functionality, we’ve developed an additional option that allows users to set themselves as ‘Out of Office’ (OOO). This enhancement provides a popup notification to anyone attempting to assign a task to an OOO user, reminding them that the person is currently unavailable.

While this feature doesn’t prevent task assignment if absolutely necessary, it serves as a helpful reminder to consider alternative assignees or team queues.

Configuration Steps

Create a New Field: Add a new field called u_enable_ooo to the sys_user_delegate table.

Implement Client Script: Create a client script to display the popup when a user with an active delegate and enabled OOO is selected. This script should run onChange of the Assigned To (assigned_to) field. Apply the client script to relevant tables such as incidents and catalog tasks.

Here’s the script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
        return;
    }

    var ga = new GlideAjax('CustomDelegateUtils');
    ga.addParam('sysparm_name', "getOOO");
    ga.addParam('sysparm_user_id', newValue);
    ga.getXML(callback);

    function callback(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
		answer = parseInt(answer);

        // If row count from the ajax call is greater than or equal to 1, there is a valid OOO set and show the popup
        if (answer >= '1') {
            var user = g_form.getReference('assigned_to');
            alert(user.first_name + ' ' + user.last_name + ' is currently out of office, please consider assigning to someone else in this team, or the team unassigned queue.');
        }
    }
}

Create Script Include: Create a script include (CustomDelegateUtils) to perform the GlideRecord query:

var CustomDelegateUtils = Class.create();
CustomDelegateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getOOO: function() {

        // Search the sys_user_delegate table for a record where:
        // Start date is before today AND end date is after today AND u_enable_ooo is true
        userID = this.getParameter('sysparm_user_id');
        var gr = new GlideRecord('sys_user_delegate');
        gr.addEncodedQuery('starts<=javascript:gs.endOfToday()^ends>=javascript:gs.beginningOfToday()^u_enable_ooo=true');
        gr.addQuery('user', userID);
        gr.query();

        // If we have at least one record returned, then the user has a current valid OOO and we show the warning in the client script
        return gr.getRowCount();
    },

    type: 'CustomDelegateUtils'

});

Conclusion

This enhancement to ServiceNow’s delegate feature significantly improves task management efficiency by providing timely notifications about user availability. By implementing this Out of Office functionality, organizations can reduce delays in task assignments, improve communication, and ultimately enhance their overall workflow management in ServiceNow.