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-17-2019 02:24 AM
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);
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2019 03:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2019 03:30 AM
replace ) with } on line 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2019 04:14 AM
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);
}