The CreatorCon Call for Content is officially open! Get started here.

Business Rule - Check if a Change Request has a Change Task

traviswarren
Kilo Expert

Hello all,

I have a requirement where a change request must have at least one change task before setting the state to requested.   Below is where I stand at the moment.

condition: current.state.changesTo(9)

  var tr = new GlideRecord('change_task');

  tr.addQuery('change_request', current.change_request);

  tr.query();

  if(!tr.next())

  {

  gs.addErrorMessage("Please create a Change Task");

  current.setAbortAction(true);

  }

thanks in advance.

1 ACCEPTED SOLUTION

Very minor change and now its working. Still should have worked before but overall happy that its working now.




var ctask = new GlideRecord('change_task');


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


ctask.query();


if(!ctask.next())


{


  gs.addErrorMessage("Please create a Change Task");


  current.setAbortAction(true);


}




Thanks!


View solution in original post

6 REPLIES 6

Thanks for clearing that up for me. I hope I can help you get past this so that you can keep being awesome with others tasks too!



There are 3 things that come to mind that could be stopping your BR from running.



1) The state never gets to 9. This could be because state never gets changed to 9 because the value of Requested is not actually 9.


2) Your BR is set to after insert or update so the record gets saved anyway and your error message still shows up.


3) If the value of Request does get to 9, then the request does have a change task associated with it which is why your BR isn't running.




You can run some debug statements to check into that third option.





debug('First line in BR. State is 9!');


var tr = new GlideRecord('change_task');


tr.addQuery('change_request', current.change_request);


tr.query();


if(!tr.next()){


  debug('In !tr.next. That means there is no task associated with this request.');


  gs.addErrorMessage("Please create a Change Task");


  current.setAbortAction(true);


  debug('Action aborted.');


}




function debug(message){


  gs.log('[' + new Date().getTime() + ']' + message, 'myBR');


}



Can you send a screen shot of what error you are getting? Do you see anything happening or is nothing happening and that is the clue? Be as specific as possible so I can help you out specifically.


Very minor change and now its working. Still should have worked before but overall happy that its working now.




var ctask = new GlideRecord('change_task');


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


ctask.query();


if(!ctask.next())


{


  gs.addErrorMessage("Please create a Change Task");


  current.setAbortAction(true);


}




Thanks!