Hi Ankur,

I have debugged it and this is my script

var DelegationUtil = Class.create();
DelegationUtil.prototype = {
    initialize: function() {},

    isUserOrDelegate: function(originalUserId) {
        if (!originalUserId) {
            gs.debug("[DelegationUtil] originalUserId is null or undefined.");
            return false;
        }

        var currentUserId = gs.getUserID();
        gs.debug("[DelegationUtil] Checking delegation for current user: " + currentUserId + " against original user: " + originalUserId);

        if (currentUserId == originalUserId) {
            gs.debug("[DelegationUtil] Current user is the original user.");
            return true;
        }

        var gr = new GlideRecord('sys_user_delegate');
        gr.addActiveQuery(); // Only active records
        gr.addQuery('delegate', currentUserId);
        gr.addQuery('user', originalUserId);
        gr.addQuery('starts', '<=', gs.nowDateTime());
        gr.addQuery('ends', '>=', gs.nowDateTime());
        gr.query();

        var hasDelegation = gr.hasNext();
        gs.debug("[DelegationUtil] Delegate record found: " + hasDelegation);

        return hasDelegation;
    }
};

But the debug log only shows this which is referencing to my correst user sys_id but it does not reflect that it has found a delegation, may I know why so?

ChuanYanF_0-1749087031455.png