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

Restrict change closure if there are open tasks

ramkrish
Kilo Contributor

Hi,

I have coded as per below in an before update BR.

var task=new GlideRecord('Change_Task');

  task.addJoinQuery('change', current.number,'change_task.number');

  task.query();

  while (task.hasnext())

  {

  if (task.state != 'Closed Complete')

  gs.addErrorMessage('Ticket cannot be moved to Closed');

  }

But it is not working. Can you help here?

10 REPLIES 10

anonymous13
Tera Expert

Change Tasks should only be able to be closed if the change state is Implement or Review. else show error message

Before Business rule: 

anonymous13_0-1689588739164.png


(function executeRule(current, previous /*null when async*/ ) {
gs.addErrorMessage(gs.getMessage('In order to close a change tasks, your Change Request must be in the Implement state '));
current.setAbortAction(true);
gs.setRedirectURL(current);
current.state = previous.state;      // it will help us to set previous state after load the form
var changeTask = new GlideRecord('change_task');
if (changeTask.next()) {
changeTask.update();
}
})(current, previous);


I hope this helps. Please mark correct/helpful based on impact