- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 05:37 AM
I want to close all child incidents before closing parent incident, if any one child incident not closed the parent incident should not be closed should populate a error message
I tried the code below but, If I try to close one child Incident parent incident is also getting closed
I tried many solutions in community but, none of them work please help me with this
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', current.sys_id);
inc.addQuery('sys_id', '!=', current.sys_id);
inc.addActiveQuery();
inc.query();
if (!inc.next()) {
var parInc = new GlideRecord('incident');
parInc.addQuery('sys_id', current.parent_incident);
parInc.query();
if (parInc.next()) {
parInc.state = 6;
parInc.active = false;
parInc.update();
}
}
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 03:36 AM
Hi Vijay,
Actually in resolved state the active flag is true only and in closed state it is setting to false.
Try updating the filter condition as shown below:
Remove the resolved part and try putting infomessage inside the code and see which info message is coming in the below sctipt:
//Check if all hte task are closed or not
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', current.getValue('parent_incident'));
inc.addActiveQuery();
inc.query();
if(!inc.hasNext()) {
gs.addInfoMessage('@inside Loop ' + current.getValue('parent_incident'));
//If task are closed then closed the parent ticket.
var parInc = new GlideRecord('incident');
parInc.get(current.getValue('parent_incident'));
gs.addInfoMessage('parent incident nubmer ' + parInc.getValue('number'));
parInc.state = 6 //State value which you want to set
parInc.update();
}
gs.addInfoMessage('Inside BR');
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 11:07 PM
Yes I added those conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 10:13 PM
HI Vijay,
You have to write an on before BR on incident table and condition would be when state changes to closed:
The script would be:
if(JSUtil.nil(current.parent_incident)) //Checking if this is parent incident or child incident
{//If it is parent incident then only it will proceed
//Update all the child tickets
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', current.getUniqueValue());
inc.addActiveQuery();
inc.query();
while(inc.next()) {
inc.state = 6;
inc.active = false;
inc.update();
}
}
The script will first close all the child incident then close the parent incident
Please mark helpful and correct if it works.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 10:35 PM
Hi CB,
Thank you for quick reply
I tried the code but, when I try to resolve one child incident all child incidents and parent incident is also resolving
My requirement is I should not able to resolve parent incident until all child incident's are closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 10:42 PM
Hi Vijay,
I just misunderstood the requirement so the update script would be:
if(JSUtil.nil(current.parent_incident)) //Checking if this is parent incident or child incident
{//If it is parent incident then only it will proceed
//Update all the child tickets
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', current.getUniqueValue());
inc.addActiveQuery();
inc.query();
if(inc.hasNext()) {
gs.addErrorMessage('You cannot close the parent ticket until the child incident are closed');
current.setAbortAction(true);
}
}
Mark helpful and correct if it helps.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 11:03 PM