How to call script include in a module url argument to get dynamic delegated users?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 08:30 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 11:38 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 11:47 PM
Hi Ankur, this is my script include
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;
}
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 11:50 PM
you are returning true/false but you should return sysId of delegate or user as per your requirement
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 09:35 PM - edited 06-09-2025 09:37 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 10:33 PM
Sorry J Siva, but do u mean I create the dynamic filter option as below like this?