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

Alicja1
Kilo Contributor

Hi David,

 

Thank you! It prevents setting the Change to the next status and displays the error message, but somehow, after clicking the button of the next State, it still changes the state in the ticket... When I exit the ticket and go back to it, the status is back to 'New' so functionally, it works, but somehow it still displays the status change after clicking the button and staying in the ticket.

I wonder if this is related to an UI Action and if you would know how to change it?

 

Alicja

UI actions run clients side and server side code so when you click the button it changes the state but your business rule will prevent the form from being submitted.

You could write a function in a script include and call it in the condition field of all the change UI actions so that the buttons are not visible whilst there are still active tasks. Something like below would work:

/*
add the following to the condition of the UI action:
 && !checkTasks(current.getUniqueValue())
*/

//call the script include checkTasks, delete the class syntax that autopopulates when you enter the name

function  checkTasks(sysID){
var gr = new GlideRecord('change_task');
gr.addQuery('change_request', sysID);
gr.addActiveQuery();
gr.setLimit(1);
gr.query();
return gr.hasNext();
}

Hi Alicja,

Did this work? If your question is answered, please can you mark my answer correct to close the thread down?

Alicja1
Kilo Contributor

Hi David,

Unfortunately, it didn't work. I did the following:

- In the UI Action for moving the State of the Change to 'Scheduled', I have added && !checkTasks(current.getUniqueValue()) to the condition field that was already populated with other conditions;

- Added:

function checkTasks(sysID){
var gr = new GlideRecord('change_task');
gr.addQuery('change_request', sysID);
gr.addActiveQuery();
gr.setLimit(1);
gr.query();
return gr.hasNext();
}

to the script. There was a different script already in place, so I added the above by pasting it under the original script.

 

Do you have any other suggestions?

Alicja

HI Alicja,

You need to add that script as a script include, adding it to the script part of the UI action doesn't make it callable in the conditions.

example of what it should look like is below:

find_real_file.png