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

Thanks David, I'm going to test now and let you know.

Alicja1
Kilo Contributor

Hi again,

It didn't work. When I set the state of the Change with incomplete CTASK to Scheduled, I get an error bar with message 'You cannot proceed a change with active tasks against it', but I cannot close the bar not scroll down in the change ticket, it seems like the record form has been blocked. I cannot even leave it by clicking on 'Save & exit'. 

 

Oops, my bad, because the script is reverting the state to the oldValue, it's re-triggering the onChange script and running is recursively. Hence why your form is getting locked up! Change the client script as below so it won't run the ajax call when the state is reset to the oldValue:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '' || g_form.getValue('state') == oldValue) {
		return;
	}
	
	var ga = new GlideAjax('ChangeTaskUtils');
	ga.addParam('sysparm_name', 'checkTasks');
	ga.addParam('sysparm_change', g_form.getUniqueValue());
	ga.getXMLAnswer(returnAjaxData);
	
	function returnAjaxData(response){
		if(response){
			g_form.addErrorMessage('You cannot proceed a change with active tasks against it');
			g_form.setValue('state', oldValue);
		}
	}
}

Alicja1
Kilo Contributor

Hi David, that fixed the issue with the locked form, thanks. It still does not solve the issue with the progress bar, that's the only thing that is not working at the moment. 

find_real_file.png

I am trying to find which script/setting defines the changes in the progress bar states, but no luck...

Btw, is there a way to remove the box with 'invalid update' message?

 

Alicja1
Kilo Contributor

Hi David,

I tried combining all the items that you have suggested in this conversation:

- Business Rule;

- added the && !checkTasks(current.getUniqueValue()) condition in the UI action;

- Script Include - checkTasks

- Script Include - ChangeTaskUtils

and so far it gave me the bast results. The only thing now is that when the CTASK is closed and I click on 'Schedule' button in the Change ticket, at the moment when the new form is being submitted, I see the bar with the error message 'Please ensure all associated tasks...' popping up for a second, and then it disappears... Strange. It happens every time I change the State of the ticket. 

Can this be adjusted?