Help with the below Business rule

Pooja Khatri
Tera Contributor

Hi All , 

 

I am using the below script in one my function in my Business rule , the entire script is written in the function 

 

function change(){
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) {
 return false ;
}
else {
 return true ;
 }
  }
  else {
 return false ;
 }}
 
and I am callling the function in the below way 
 
var isNormal = change();
 
I want to now want to trigger an event == approve.insert 
 
I want to utilize function return to trigger or not trigger the approval.insert event , if the conditions in my function are true it should trigger event approve.insert
 
I wan to to build the logic for above statement in the below code : 
 
if (current.state.changes() && current.state == 'requested') {
    var event = "approve.insert";
    if (req)
        event = "req.approve.insert";
    else if (tsk)
        event = "tsk.approve.insert";

    gs.eventQueue(event, current, gs.getUserID(), gs.getUserName());
    var cmt = getComment(isFD, getApproverUserName(current.approver), "Approve");
    updateTask(current, cmt);
}
 
Can anyone help me to fix this logic ?
5 REPLIES 5

Could you please provide Error. Try to add gs.logs in script so you will get to know where is breaking