Close all change tasks when state is in Review state

hugogomes
Giga Expert

Hi community,

I am trying to close all the change tasks open for any change request that reaches the Review state.
I will not change the workflow to have a script include since I only want for this to happen to certain changes, in this case for the ones I have an Integration with Remedy.

The state in the change workflow is controlled by UI Action, this means that to change the state, it needs to be done manually.

In the case of the integration, we receive a message that automatically change the state to Review. Review is the last state of the workflow.

I have tried to include a BR to have the tasks closed but it seems that it is not working, and I think it should... since I have picked up the code we have on wiki.

BR: onBefore

Table: change_request

var ctask = new GlideRecord('change_task');

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

ctask.query();

while(ctask.next()){

ctask.state.setValue(3);

ctask.work_notes = "Task automatically closed";

}

current.work_notes = "Tasks automatically closed";

Instead of having the "Closed" state I have "Closed Incomplete".

Any idea of why this is happening?

Thank you in advance!

1 ACCEPTED SOLUTION

I've found a solution for this.



Dumb mistake, it was only missing a ctask.update(); inside the while loop.



All working now


View solution in original post

7 REPLIES 7

I have already check and it is correct, its 3.


hugogomes
Giga Expert

Now I have also to have this in an UI Action and it doesn't work as well.



The task are created in a subflow, is this the problem?



In the UI Action I have



new WorkflowApprovalUtils().cancelAll(current);


new Workflow().restartWorkflow(current);




if (current.number.indexOf("DMN") >= 0){


current.state = 100;


}


else{


current.u_escalated_to_gcab = false;


current.state = -4;



var ctask = new GlideRecord("change_task");


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


ctask.query();


while(ctask.next()){


ctask.state = 3; //not working


ctask.work_notes = "Test work note"; //not working


}


}


current.update();




Any ideas on this?


I've found a solution for this.



Dumb mistake, it was only missing a ctask.update(); inside the while loop.



All working now