- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 11:46 AM
Hi Community,
I'm running into an issue with filtering approvals in the approval widget, or from a report on the approval table. When I try to hide a specific catalog item, change requests are also getting filtered out.
Report Filter: "Approval for > Item" is not "Item Name"
The end goal is to hide a specific catalog item from the approval widget as we're using a custom form for these approvals. I cloned the widget and modified this section of the script with a query to hide the catalog item. However, this is hiding all change approvals as well, and I'm not sure why.
Widget:
data.myApprovals = getMyApprovals();
gr.addQuery("approver", data.myApprovals);
gr.addQuery('sysapproval.ref_sc_req_item.cat_item', "!=", '36d7917c1bd40950b3c164abbc4bcbc3'); //added to hide catalog item
gr.orderBy("sys_created_on");
gr.query();
var rowCount = gr.getRowCount();
var approvals = [];
var ids = [];
var source_tables = [];
Does anyone know why, or how I can get around this?
Thank you,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 04:56 PM
How is the getMyApprovals() function defined? That is probably where you want to add the filter condition for removing that catalog item. The query is also probably removing change requests because the catalog item filter condition is invalid for those class of records.
So you will want to update the query to have an OR all of these conditions must be met specific to sc_req_item approvals that is equivalent to below:
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 04:56 PM
How is the getMyApprovals() function defined? That is probably where you want to add the filter condition for removing that catalog item. The query is also probably removing change requests because the catalog item filter condition is invalid for those class of records.
So you will want to update the query to have an OR all of these conditions must be met specific to sc_req_item approvals that is equivalent to below:
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 05:59 PM
Thank you! I think I have to add the query to the getMyApprovals business rule, but I'm not quite sure where to add it's also checking approving delegates and group approvals.
If you know how this could be accomplished, could you please advise? I'm having trouble making sense of how the scripts interconnect here. This is the BR script:
function getMyApprovals() {
var u = gs.getUserID();
var answer = new Array();
var i = 0;
answer[i++] = new String(u);
var g = new GlideRecord("sys_user_delegate");
g.addQuery("delegate", u);
g.addQuery("approvals", "true");
g.addQuery("starts", "<=", gs.daysAgo(0));
g.addQuery("ends", ">=", gs.daysAgo(0));
g.query();
while( g.next())
answer[i++] = new String(g.user);
return answer;
}
function getMyAssignments() {
var u = gs.getUserID();
var answer = new Array();
var i = 0;
answer[i++] = new String(u);
var g = new GlideRecord("sys_user_delegate");
g.addQuery("delegate", u);
g.addQuery("assignments", "true");
g.addQuery("starts", "<=", gs.daysAgo(0));
g.addQuery("ends", ">=", gs.daysAgo(0));
g.query();
while( g.next()) {
answer[i++] = new String(g.user);
}
return answer;
}
function isApprovalMine(gr) {
var approver = gr.approver + '';
// if this is the sysapproval_group table, gr.approver
// would evaluate to 'undefined'
if (!gr.isValidField('approver'))
approver = '';
var approverSysId = gr.sys_id + '';
// Check if approver is nil due to being on a list
// of records that contain a related list of approvers
// or due to checking a group approval
if(JSUtil.nil(approver) && JSUtil.notNil(approverSysId)) {
// Look at the sysapprover_approval table
var app = new GlideRecord('sysapproval_approver');
if (gr.getTableName() == 'sysapproval_group')
app.addQuery('group', approverSysId);
else
app.addQuery('sysapproval', approverSysId);
app.query();
while(app.next()) {
approver = app.approver;
if(checkAllApprovers(approver))
return true;
}
}
return checkAllApprovers(approver);
}
function checkAllApprovers(approver){
if(JSUtil.nil(approver))
return false;
var apps = getMyApprovals();
for (key in apps) {
if (apps[key] == approver)
return true;
}
return false;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 06:11 PM
Ok thanks that is helpful. With that in mind you found the correct code to modify in your original post. If you edit the script to below I think it should work:
data.myApprovals = getMyApprovals();
/*
gr.addQuery("approver", data.myApprovals);
gr.addQuery('sysapproval.ref_sc_req_item.cat_item', "!=", '36d7917c1bd40950b3c164abbc4bcbc3'); //added to hide catalog item
*/
gr.addEncodedQuery(gs.getMessage('approver={0}^sysapproval.sys_class_name!=sc_req_item^NQapprover={0}^sysapproval.sys_class_name=sc_req_item^sysapproval.ref_sc_req_item.cat_item!=36d7917c1bd40950b3c164abbc4bcbc3', data.myApprovals));
gr.orderBy("sys_created_on");
gr.query();
var rowCount = gr.getRowCount();
var approvals = [];
var ids = [];
var source_tables = [];
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry