Prevent users from moving the Change to the next State before the CSTASK is completed

Alicja1
Kilo Contributor

I have a Workflow for a Standard Change in which I would like to prevent the users from moving the Standard Change to the next State (this is done manually by clicking on the button or setting the 'State' filed to the desired state) before the CTASK created on this state (creation via Workflow) is set to one of the 'Complete' statuses. 

In situation when the user clicks on the button of the next State and the CSTASK is still open, a message should be displayed indicating that the State cannot be changed because the task(s) have not been completed.

How can I best achieve this? I have read many posts and some people advise UI Actions, others Business Rules but due to my limited knowledge of scripting I cannot figure it out myself..

I appreciate your help!

Alicja

31 REPLIES 31

Dubz
Mega Sage

I think the best solution is a before update business rule set to run when the state changes. Run something like the code below and it should check for open tasks and throw up an error message if there are open tasks.

var gr = new GlideRecord('change_task');
gr.addQuery('change_request', current.getUniqueValue());
gr.addActiveQuery();
gr.setLimit(1);
gr.query();
if(gr.hasNext()){
gs.addErrorMessage('Please ensure all associated tasks are completed before progressing the change');
current.setAbortAction(true);
)

Alicja1
Kilo Contributor

Hi David,

The script does not seem to be correct - I am getting errors. What should I put in the Condition field for the business rule script?

find_real_file.png

replace ) with } on line 11

typo!

var gr = new GlideRecord('change_task');
gr.addQuery('change_request', current.getUniqueValue());
gr.addActiveQuery();
gr.setLimit(1);
gr.query();
if(gr.hasNext()){
gs.addErrorMessage('Please ensure all associated tasks are completed before progressing the change');
current.setAbortAction(true);
}