Need to exclude the requestor from approving the change request

suryaogeti1
Tera Contributor

Hi All

I am using the flow designer for approval process but here i need to exclude the requestor from approving the change request, how can we achieve this. In rules section can we use both code and configuration, i have tried it is not working for me

suryaogeti1_0-1779101450512.png


(function execute(inputs, outputs) {

    // Get the Change Request record
    var changeGR = new GlideRecord('change_request');
    if (!changeGR.get(inputs.changeSysId)) {
        return;
    }

    // Determine requester (requested_by preferred, fallback to opened_by)
    var requester = changeGR.requested_by || changeGR.opened_by;
    if (!requester) {
        return;
    }

    // Remove requester from approval list if present
    var appr = new GlideRecord('sysapproval_approver');
    appr.addQuery('sysapproval', changeGR.sys_id);
    appr.addQuery('approver', requester);
    appr.addQuery('state', 'requested');
    appr.query();

    while (appr.next()) {
        appr.deleteRecord();
    }

})(inputs, outputs);

 

4 REPLIES 4

Anurag Tripathi
Mega Patron

HI,

Check Amit's reply here, his is on RITM but same applies on Change as well

Prevent Approval from requestor - Requested Item - ServiceNow Community

-Anurag

I am not getting where they have written the code in flow designer, i tried but it is not working for me

Tanushree Maiti
Tera Patron

Hi @suryaogeti1 

 

Create a before-insert Business Rule on the sysapproval_approver table to validate whether the approver is requested_for  user of the RITM.

If condition is met, prevent the record from being inserted by using current.setAbortAction(true).

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankur Bawiskar
Tera Patron

@suryaogeti1 

you can use scripted flow approval

Scripted Approvals in Flow Designer with Flow Variables 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader