checking if change tasks have been approved before requesting approval for a change request

donatello
Tera Contributor

I am trying to write a business rule to check all change tickets to make sure that they have been approved before a change can be placed into pending or "requested for approval"". my script is not working for some reason and I would love if the community would help me out. Thanks in advance

function onBefore(current, previous) {

  checkChildTasks();

function checkChildTasks() {

      var grChild = new GlideRecord("change_task");

      grChild.addQuery('change_request', current.sys_id);

      grChild.addQuery('Approval',"CONTAINS","approved");

      grChild.query();

while(grChild.next()){  

      if (grChild.result == "approved" || grChild.result == "skipped")

      answer = true;  

      else{  

      answer = false;  

      return;  

  }  

  }  

}  

}

8 REPLIES 8

donatello
Tera Contributor

function onBefore(current, previous) {


  checkChildTasks();


function checkChildTasks() {


      var grChild = new GlideRecord("change_task");


      grChild.addQuery('change_request', current.sys_id);


      grChild.addQuery('Approval',"CONTAINS","approved");


      grChild.query();


while(grChild.next()){  


      if (grChild.result == "approved" || grChild.result == "skipped")


      answer = true;  


      else{  


      answer = false;  


      return;  


  }  


  }  


}  


}


Here you go



function onBefore(current, previous) {  


  if(checkChildTasks()=="true"){


current.setAbortAction(true);


}


function checkChildTasks() {  


      var grChild = new GlideRecord("change_task");  


      grChild.addQuery('change_request', current.sys_id);  


      grChild.addQuery('approval',"approved");  


      grChild.query();  


if(grChild.hasNext()){      


      return true;


  }      


  }          


}    


thanks but that did not work, I when I click on request approval it still goes to pending with the change tasks not approved


Can you post the screenshots of your business rule and your business rule conditions