change request

Bhavani1995
Tera Contributor

answer = {
    // Configure policy inputs here
    u_vp_approval_mandatory: false
};
var vp_approval_required = false;
var gr_conflict = new GlideRecord('conflict');
gr_conflict.addEncodedQuery("change=" + current.sys_id + "^type=blackout^schedule.ref_cmn_schedule_blackout.u_vp_approval_req=true");
gr_conflict.query();
if (gr_conflict.next()) {
    // If VP field is empty, no VP approval is required
    if (!current.assigned_to.u_vp) {
        vp_approval_required = false;
        current.work_notes = "Current User does not have a VP. VP approval NOT required."; // Optional
    } else if (current.assigned_to.manager != current.assigned_to.u_vp) {
        vp_approval_required = true;
    } else {
        // manager and VP are same, do not require approval
        vp_approval_required = false;
    }
}

 

if (vp_approval_required) {
    answer.u_vp_approval_mandatory = true;
}

for this script work notes is not being updated on the change request form when assigned user vp is empty

4 REPLIES 4

Satyapriya
Mega Sage

Hello @Bhavani1995 ,
Can you please try with this


answer = {
u_vp_approval_mandatory: false
};

var vp_approval_required = false;
var gr_conflict = new GlideRecord('conflict');
gr_conflict.addEncodedQuery("change=" + current.sys_id + "^type=blackout^schedule.ref_cmn_schedule_blackout.u_vp_approval_req=true");
gr_conflict.query();

if (gr_conflict.next()) {

// If VP field is empty, no VP approval is required
if (!current.assigned_to.u_vp) {
vp_approval_required = false;

current.work_notes = "Current User does not have a VP. VP approval NOT required.";
current.setWorkflow(false);
current.update();
}
else if (current.assigned_to.manager != current.assigned_to.u_vp) {
vp_approval_required = true;
}
else {
// manager and VP are same, do not require approval
vp_approval_required = false;
}
}

if (vp_approval_required) {
answer.u_vp_approval_mandatory = true;
}

Ankur Bawiskar
Tera Patron
Tera Patron

@Bhavani1995 

where is this script written?

share some screenshots and detailed business requirement

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

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

This is written for change request non standard workflow

This is written for change request non standard workflow