Prevent parent ticket from closing if child ticket has a open task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 01:03 PM - edited 11-09-2022 01:14 PM
Hello,
I have a requirement to prevent a parent ticket from closing if the child ticket has an opened task assigned to it. As of right now, I have two BR's.
1. Close child ticket when parent ticket is closed.
2. Prevent ticket from closing if there is a open task within it.
Separately, both works fine. However, when both are active, the 2nd BR (Prevent ticket from closing if there is an open task) is breaking the 1st BR (close child ticket when parent ticket is closed). What is happening when both are active is, the parent ticket's state will change to "Resolved". However, an error message appears to let the user know there is an open task record. The child ticket is not closed.
When I close the open task; then go back and resolve the parent ticket, now the child ticket's state does not change to resolve as well.
Can someone help?
Script to prevent ticket from closing if there is open task (Before, update, insert)
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('table name'); // This will be the child task table
gr.addQuery('parent',current.sys_id); ///field on the child table where the parent record number
gr.addActiveQuery();
gr.query();
if(gr.next()){
gs.addErrorMessage('Please close Task ticket before closing this ticket.');
current.setAbortAction(true);
}
})(current, previous);
Script to close child ticket when parent ticket closes (After, update, insert)
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var closedChild = 0;
var grUUT= new GlideRecord('table name');
grUUT.addQuery('u_parent_uut.current.sys_id);
grUUT.query();
while(grUUT.next()){
grUUT.state = current.state;
grUUT.update();
var msg = "UUT" + task.number + ' resolved based on resolution of Parent '+me.number;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 05:01 PM
You’re going to have to check if your child records have any open tasks in the close child ticket BR as well.
Otherwise you’ll have to check to see if you successfully updated each record before closing the parent.
If you’re going to use logic like this I suggest that if you’re closing the parent and it’s supposed to close the child, you should also close all the tasks associated to avoid the conflict.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 06:20 AM - edited 11-10-2022 06:21 AM
Hi Mike,
How do I check if my child tickets have open task? Can you help from the 2 scripts I provided?
Is there an easier way to do this?