Prevent users from moving the Change to the next State before the CSTASK is completed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2019 01:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2019 04:05 AM
Hi David,
I have created the script include and it hides the 'Schedule' button in my ticket, but the user is still able to change the state via a drop-down menu in the 'State' filed - see attached:
When I set the State to "Scheduled", it still goes to Scheduled on the progress bar above, but shows me error message and 'invalid update' message. After re-submitting the form, the state is back to "New", but I would like the progress bar to stay on New until the tasks in completed and the Schedule button is clicked.
How can this be fixed?
Alicja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2019 05:12 AM
Lol.
Ok so perhaps an onChange client script on the state field would work? You can make an ajax call to a script include onChange of the state field that will check whether there are open tasks or not, if there are open tasks it will revert the value and throw up an error message eg:
Client Script:
var ga = new GlideAjax('ChangeTaskUtils');
ga.addParam('sysparm_name', 'checkTasks');
ga.addParam('sysparm_change', current.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);
}
Script Include:
// name it the same as you ajax call (ChangeTaskUtils as above) and tick the client callable box, add the code below within the syntax that autopopulates
checkTasks: function(){
var changeID = this.getParamter('sysparm_change');
var gr = new GlideRecord('change_task');
gr.addQuery('change_request', changeID);
gr.addActiveQuery();
gr.setLimit(1);
gr.query();
return gr.hasNext();
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2019 06:47 AM
you can use the same script include, assuming you script include returns answer as yes
ans write a on load client script to remove option
g_form.removeOption('state', '10'); //assuming schedule value is 10
regards
rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2019 06:51 AM
I'd advise against removing the option onLoad, it might be confusing for users if they want to progress the change but can't find any way of doing so. You could pop up an error message but that would be annoying for users just working on the ticket, no looking to change the state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2019 06:59 AM