Change Approvals - Report on Changes the proceeded without approval

JW8
Giga Contributor

Hi all,

 

We are having an issue (being looked at by our devs) where some changes are proceeding without approval, with various ways of getting there.  The issue itself is in hand, but where we are having problems is in identifying affected change records.

 

We effectively need to report

 

  • Where changes are in Scheduled/Implement/Review/Closed and there are:
    • No Approved approvals; or
    • Where there are no approvals added at all

 

We are really struggling to get this to work, hoping someone can point us in the right direction.

 

Thanks in advance

1 REPLY 1

PavanJ
Tera Guru

Hello @JW8 , Greetings of the day,

 

Yes you can achieve this by using below background script, please adjust states accordingly

 

// Define the Scheduled state value
var scheduledState = -2; // Adjust based on your instance state values
 
// GlideRecord for Change Request
var grChange = new GlideRecord('change_request');
grChange.addQuery('state', scheduledState); // Fetch changes in Scheduled state
grChange.query();
 
var results = [];
 
while (grChange.next()) {
    // Check if any approvals exist for this change request
    var grApproval = new GlideRecord('sysapproval_approver');
    grApproval.addQuery('sysapproval', grChange.sys_id);
    grApproval.query();
 
    if (!grApproval.hasNext()) { // No approvals exist
        results.push({
            number: grChange.number.toString(),
            sys_id: grChange.sys_id.toString(),
            short_description: grChange.short_description.toString(),
            opened_by: grChange.opened_by.getDisplayValue(),
            scheduled_date: grChange.planned_start_date.toString()
        });
    }
}
 
// Output the results
if (results.length > 0) {
gs.info("Change Requests moved to Scheduled state without approvals:");
    results.forEach(function(change) {
gs.info("Number: " + change.number + " | Description: " + change.short_description +
                " | Opened by: " + change.opened_by + " | Scheduled Date: " + change.scheduled_date);
    });
} else {
gs.info("No Change Requests found in Scheduled state without approvals.");
}
 
Please hit alike of you it is helpful to your requirement
Pavan J