Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Standard Change State Management

NilanjanB
Tera Expert

Dear Experts, 

 

I have standard changes which processes the decommission of the servers but the tasks that are created is controlled which means that the preceding task is dependent on the previous task.. but when the first task is closed after the change is moved to implement before the next task is opened, and the state changes to Review but the tasks have not even been populated and there are other tasks pending as well. It is an out of the box behaviour, but how to prevent that. Please help!!!

1 ACCEPTED SOLUTION

NilanjanB
Tera Expert

I worked on the business rule it worked to held on the implement state  

(function executeRule(current, previous /*null when async*/ ) {
    var review_value = '0';

    // Add your code here
    var activeTask = new GlideRecord("change_task");
    activeTask.addQuery("change_request", current.sys_id);
    activeTask.addQuery("state", "NOT IN ", "3,4,7");
    activeTask.query();
    if (activeTask.hasNext()) {
        current.setAbortAction(true);
        return;
    }
    var activeFlow = new GlideRecord("sys_flow_context");
    activeFlow.addQuery("source_record", current.sys_id);
    activeFlow.addQuery("state", "IN", "IN_PROGRESS,WAITING,QUEUED");
    activeFlow.query();
    if (activeFlow.hasNext()) {
        current.setAbortAction(true);
        return;
    }
    current.state = review_value;

})(current, previous);

  

View solution in original post

6 REPLIES 6

I think BR is needed here mate

****************************************************************************************
Regards
Dr Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
******************************************************************************************

NilanjanB
Tera Expert

I worked on the business rule it worked to held on the implement state  

(function executeRule(current, previous /*null when async*/ ) {
    var review_value = '0';

    // Add your code here
    var activeTask = new GlideRecord("change_task");
    activeTask.addQuery("change_request", current.sys_id);
    activeTask.addQuery("state", "NOT IN ", "3,4,7");
    activeTask.query();
    if (activeTask.hasNext()) {
        current.setAbortAction(true);
        return;
    }
    var activeFlow = new GlideRecord("sys_flow_context");
    activeFlow.addQuery("source_record", current.sys_id);
    activeFlow.addQuery("state", "IN", "IN_PROGRESS,WAITING,QUEUED");
    activeFlow.query();
    if (activeFlow.hasNext()) {
        current.setAbortAction(true);
        return;
    }
    current.state = review_value;

})(current, previous);