- 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-19-2020 02:22 AM
Hi Vijay,
You have to write one more After BR on incident table:
Table - incident,
Condition - Parent incident is not empty AND
state changes to close/resolved.
The script would be:
//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()) {
//If task are closed then closed the parent ticket.
var parInc = new GlideRecord('incident');
parInc.get(current.getValue('parent_incident'));
parInc.state = 6 //State value which you want to set
parInc.update();
}
This Br will only run on child incidents closed.
Condition screenshot.
Mark helpful and correct.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 02:48 AM
Hi CB,
result is same I cant close the parent incident can we write
If("parent_incident" > 0)
{
state =6;
update();
}
some thing like that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 02:53 AM
Hi Viay,
This function is also doing the same it it checking if the current child record doesn't have any open child ticket then it will close the parent.
May be can you put info and log message inside the loop and see where its failing.
Maket sure that this child Br is written in after and where the parent is nto empty.
Can you share the scrren shot what you have done.
And update the state to close .
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 03:24 AM
- 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