- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:52 AM - edited 10-20-2025 01:41 PM
I am trying to return all approvals for a specific Catalog Item, i have the script working but i want to run when you select on a module in the navigation.
Here is my script:
var approvalTest = Class.create();
approvalTest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateApprovals: function() {
var approvals = [];
var grApprovals = new GlideRecord('sysapproval_approver');
grApprovals.addQuery('state', 'requested');
grApprovals.query();
while (grApprovals.next()) {
var grRitm = new GlideRecord('sc_req_item');
grRitm.addQuery('active', true);
grRitm.addQuery('sys_id', grApprovals.sysapproval);
grRitm.query();
if (grRitm.next()) {
approvals.push(grApprovals.getUniqueValue());
}
}
return approvals.join(',');
},
type: 'approvalTest'
});
here is the filter but it returns null , is there a way to run javascript via a filter,
here is the module setup:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 04:47 PM - edited 10-20-2025 04:52 PM
Check the sys_property glide.script.use.sandbox on your instance, you need to make the SI either client callable or sandbox enabled for the script to work in a list filter.
Also you are doing nested queries in your script, for every row of approvals your script does a query for a matching ritm. Here are two alternative ways to achieve your result in a more performant way. Either adding a join sub query or by adding dot walked conditions.
var approvalSysids = []
var itemApprovalGr = new GlideRecord("sysapproval_approver");
itemApprovalGr.addQuery("state", "requested");
itemApprovalGr.addJoinQuery("sc_req_item", "sysapproval", "sys_id")
.addCondition("active", true)
//.addCondition("cat_item", [item sysid]);
itemApprovalGr.query()
while (itemApprovalGr.next()) {
approvalSysids.push(itemApprovalGr.getUniqueValue())
}var approvalSysids = []
var itemApprovalGr = new GlideRecord("sysapproval_approver");
itemApprovalGr.addQuery("state", "requested")
.addCondition("sysapproval.sys_class_name", "sc_req_item")
.addCondition("sysapproval.active", true)
//.addCondition(""sysapproval.ref_sc_req_item.cat_item"", [item sysid]);
itemApprovalGr.query()
while (itemApprovalGr.next()) {
approvalSysids.push(itemApprovalGr.getUniqueValue())
}
Note the significantly lower sql count and response time that can be achieved using above logic instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 05:24 PM
looks good, seems you need to debug the script logic. and review lauri457 response, make sure you're returning a comma separated list of sys_ids.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 04:47 PM - edited 10-20-2025 04:52 PM
Check the sys_property glide.script.use.sandbox on your instance, you need to make the SI either client callable or sandbox enabled for the script to work in a list filter.
Also you are doing nested queries in your script, for every row of approvals your script does a query for a matching ritm. Here are two alternative ways to achieve your result in a more performant way. Either adding a join sub query or by adding dot walked conditions.
var approvalSysids = []
var itemApprovalGr = new GlideRecord("sysapproval_approver");
itemApprovalGr.addQuery("state", "requested");
itemApprovalGr.addJoinQuery("sc_req_item", "sysapproval", "sys_id")
.addCondition("active", true)
//.addCondition("cat_item", [item sysid]);
itemApprovalGr.query()
while (itemApprovalGr.next()) {
approvalSysids.push(itemApprovalGr.getUniqueValue())
}var approvalSysids = []
var itemApprovalGr = new GlideRecord("sysapproval_approver");
itemApprovalGr.addQuery("state", "requested")
.addCondition("sysapproval.sys_class_name", "sc_req_item")
.addCondition("sysapproval.active", true)
//.addCondition(""sysapproval.ref_sc_req_item.cat_item"", [item sysid]);
itemApprovalGr.query()
while (itemApprovalGr.next()) {
approvalSysids.push(itemApprovalGr.getUniqueValue())
}
Note the significantly lower sql count and response time that can be achieved using above logic instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 09:50 PM
there are lot of OOTB left nav modules which call script include.
check those and modify yours one as per that
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
