How to call script include in a module url argument to get dynamic delegated users?

ChuanYanF
Tera Guru

Dear experts,

 

I have created a script include which is DelegationUtil, which helps to check is the user a delegate of the owner. And I want to create a module list view for them, and this is how defined the URL arguments but currently is not working. How can I approach this issue?

/sn_compliance_control_list.do?sysparm_fixed_query=owner=javascript:gs.getUserID(),(new global.DelegationUtil().isUserOrDelegate(current.owner))^state=draft,review^u_testing_procedureISNOTEMPTY
9 REPLIES 9

@ChuanYanF 

please share what that script include function is returning?

It should return user sysId

also try this

Owner [IS ONE OF] javascript: global.DelegationUtil().isUserOrDelegate()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, this is my script include

ChuanYanF_0-1749538025884.png

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;
    }
};

@ChuanYanF 

you are returning true/false but you should return sysId of delegate or user as per your requirement

        return gr.delegate.toString();
OR
        return gr.user.toString();
 
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

J Siva
Tera Sage

Hi @ChuanYanF 
It's not possible to use javascript in the arguments.
As a workaround, either create a redirection or custom dynamic filter or directly use the javasctript in the filter conditions in the List of Records link type.

Redirection:
URL (from Arguments) script include not working

Custom dynamic filter:

I want to create a report listing incidents created by members of a specific group.

 

Regards,
Siva

 

Sorry J Siva, but do u mean I create the dynamic filter option as below like this?

ChuanYanF_1-1749533626224.png