Need to fix the below script in Business rule

Pooja Khatri
Tera Contributor

I want to implement the logic of when the approver is assigned to or requested by it should skip the logic in the below Business rule using an if condition ? 

 

if(task == 'change_request'){
var changeSysId = current.document_id;
var assignedto = current.approver.sys_id.toString();
var CR = new GlideAggregate('change_request');
CR.addEncodedQuery("type=Normal^sys_id=" + changeSysId + "^requested_byORassigned_to=" + assignedto);
CR.query();

 

Can anyone please help me to complete this code ?

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Pooja Khatri Here is the complete script.

 

if(task == 'change_request'){
var changeSysId = current.document_id;
var assignedto = current.approver.sys_id.toString();
var CR = new GlideAggregate('change_request');
CR.addEncodedQuery("type=Normal^sys_id=" + changeSysId + "^assigned_to=" + assignedto+"^ORrequested_by="+assignedto);
CR.addAggregate('COUNT');
CR.query();
var count = 0;
if(CR.next()){
    count = CR.getAggregate('COUNT');
}
if(count>0){
//if count is greater than 0 which means approver user of change is either a requester or an assigned_to
current.setAbortAction(true);
}

Hope this helps.

@Pooja Khatri Please mark the answer correct if it manages to address your issue.