- 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:18 PM
Hi Vijay,
The abort action is working fine and the error is also getting displayed but there is some other BR which is running and changing the state to resolved.
I simulated the same in my PDI and it was working fine and state is not setting to resolved.
Can you check if there is any customization done in your instance. And are you using before BR only. It should be in before BR only and can you share the screenshot of the BR which you have written
There is some other BR is running which is making the update .
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 11:47 PM
Hi CB,
May I know which Instance you are using (Like- NewYork, Orlando)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 11:50 PM
If I write the code below it is working fine but, when all child incident's get closed then parent is not closing
var target = new GlideRecord('incident');
target.addQuery('active','true');
target.addQuery('parent_incident',current.sys_id);
target.query();
if (target.next())
{
current.setWorkflow(false);
current.state = previous.state;
gs.addInfoMessage('Please close child task');
gs.setRedirect(current);
current.setAbortAction(true);
} })(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 11:58 PM
Hi Vijay ,
I tried in Madid and Orlando both are working fine.
The BR is on incident table and condition is -- state changes to resolved.
It aborting the action and only on the form it will show for some time but in the backend it will not save. Try reloading the page once you click on resolve button it wil show you error and if you reload the page it won't set the value.
May be you are just referring the client side.
script:
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);
}
}
Screen shot:
Script :
Mark helpful and correct if it works.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 02:03 AM
Hi CB,
It's working fine Thank you
But, after closing last child incident parent should automatically close it's not closing