How to create report of RITMs with No approval in association with workflow?

MohammadAtR
Tera Contributor

RITM with No Approval

 

This scenario is valid if there is workflow being used and for some reason the approval stage has no approval in it.

 

1. Create a script include named 'RITMnoApproval' with client callable and sandbox enabled as ticked.

Code:

var RITMnoApprover = Class.create();
RITMnoApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRITMnoApprover: function() {
var ritmList = []; // Array to hold the sys_ids of RITMs that DO have approval records
var noritmList = []; // Array to hold the sys_ids of RITMs that DO NOT have approval records
// 1. Query the Approval table for all RITM-related approval records
var grApp = new GlideRecord('sysapproval_approver');
grApp.addQuery('source_table', 'sc_req_item');
// Add any state filtering if needed, e.g., only those currently active/pending
// grApp.addQuery('state', 'requested');
grApp.query();
while (grApp.next()) {
// Collect the sys_id of the RITM that has an approval record
ritmList.push(grApp.sysapproval.toString());
}
// 2. Query the RITM table
var grRITM = new GlideRecord('sc_req_item');

// Filter for RITMs that should be awaiting approval
grRITM.addQuery('approval', 'requested'); // or 'in progress', depending on your workflow

// EXCLUDE RITMs found in the approval table list
if (ritmList.length > 0) {
grRITM.addQuery('sys_id', 'NOT IN', ritmList.join(','));
}

grRITM.query();

//gs.print('RITMs with no approvers:');
while (grRITM.next()) {
noritmList.push(grRITM.sys_id.toString()); // Print the RITM number
}
return noritmList;
},

type: 'RITMnoApprover'
});

 

2. Create a report with table as 'sc_req_item', list view and give filter condition as

sys_id 'is one of' javascript: new global.RITMnoApprover().getRITMnoApprover()

 

Kindly mark this article as helpful or drop doubts in comments, if any.

1 REPLY 1

Tanushree Maiti
Mega Sage

You would need to create a database view with a left join with catalog task and approver table.

TanushreeMaiti_0-1771515442048.png

 

TanushreeMaiti_1-1771515498399.png

TanushreeMaiti_2-1771515537205.png

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: