Restrict change closure if there are open tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 06:08 PM
Hi,
I have coded as per below in an before update BR.
var task=new GlideRecord('Change_Task');
task.addJoinQuery('change', current.number,'change_task.number');
task.query();
while (task.hasnext())
{
if (task.state != 'Closed Complete')
gs.addErrorMessage('Ticket cannot be moved to Closed');
}
But it is not working. Can you help here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 06:25 PM
Hi Rama,
You need to write a before Update Business rule on Change Request (change_request) table to achieve your requirement. Please find the script and screenshots below.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('change_task');
gr.addActiveQuery();
gr.addQuery('change_request',current.sys_id);
gr.query();
if (gr.next()) {
gs.addInfoMessage('Please close the related Change tasks first');
current.setAbortAction(true);
}
else{
gs.addInfoMessage('You have Successfully Closed the Change Request');
}
})(current, previous);
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 01:00 AM
Hi ramkrish,
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 03:20 AM
Thanks Amlan for the reply.
In the above code the condition is not mentioned to check whether the task is open or not.@
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 03:27 AM
Hi Rama,
Please check the line number 4 where I have check whether the Tasks are Active or not. By default, whenever any task is closed it is marked as Inactive. So automatically line number 4 will filter only those Change tasks which are active. I believe this is what we need to check.
Still, if you explicitly want to query with the State of the Change task, then please add the below line after line number 4:
gr.addQuery('state', '3'); //Check the 'Closed' state value is '3'
I hope this helps. Please mark correct/helpful based on impact