Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Change request

satya1995
Tera Contributor

answer = {
    u_svp_approval_mandatory: false,
    u_svp_no_vp: false,
    u_evp_approval_mandatory: false // Add EVP approval flag
};
 
var svp_approval_required = false;
var svp_no_vp_required = false;
var evp_approval_required = false;
 
var gr_conflict = new GlideRecord('conflict');
gr_conflict.addEncodedQuery("change=" + current.sys_id + "^type=blackout^schedule.ref_cmn_schedule_blackout.u_svp_approval_req=true");
gr_conflict.query();
 
if (gr_conflict.next()) {
    if (current.assigned_to.u_management_level < 5 && current.assigned_to.manager && current.assigned_to.manager.u_management_level < 6) {
        svp_approval_required = true;
    }
 
    if (!current.assigned_to.u_vp && current.assigned_to.u_director && current.assigned_to.u_director.manager && current.assigned_to.u_director.manager.u_management_level == 6) {
        svp_no_vp_required = true;
    }
 
    // Trigger EVP approval if no VP and no SVP, and director's manager level above 6
    if (!current.assigned_to.u_vp &&
        !current.assigned_to.u_svp &&
        current.assigned_to.u_director &&
        current.assigned_to.u_director.manager &&
        current.assigned_to.u_director.manager.u_management_level > 6) {
        evp_approval_required = true;
    }
}
 
if (svp_approval_required) {
    if (!current.assigned_to.u_vp || !current.assigned_to.u_vp.manager) {
        current.work_notes = "Current User doesn't have an SVP";
    }
    answer.u_svp_approval_mandatory = true;
}
 
if (svp_no_vp_required) {
    answer.u_svp_approval_mandatory = false;
    answer.u_svp_no_vp = true;
}
 
if (evp_approval_required) {
    answer.u_svp_approval_mandatory = false;
    answer.u_svp_no_vp = false;
    answer.u_evp_approval_mandatory = true;
}
this is not triggering approvals to evp when vp and svp are empty how to modify this so that it should trigger approval to evp in the workflow

2 REPLIES 2

miftikhar20
Kilo Patron

 

Hi satya1995 ,

 

The reason the EVP approval isn't triggering is that the current logic uses separate if statements, which can cause a conflict if both SVP and EVP conditions are met.

 

To resolve this, the final approval logic needs to be restructured using an if-else block. By prioritizing the EVP check at the top of this block, the system will correctly trigger EVP approval when it's required and ignore the other approvals.

 

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Ankur Bawiskar
Tera Patron

@satya1995 

what's your requirement and where you wrote this script?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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