- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 05:15 AM
Hello,
i have written a before business on update for incident table with condition "incident state is resolved"
first i want to get the count of child incidents with state not equals to closed
and after that, if all child incidents are closed, state of parent incident should be resolved ,otherwise show error message that close the child incidents
business rule:
(function executeRule(current, previous /*null when async*/) {
var closedchild=0;
var gr= new GlideRecord('incident');
gr.addQuery('parent_incident',current.sys_id);
gr.query();
var countofchild= gr.getRowCount();
gs.addInfoMessage("child incidents which are not closed are" +countofchild );
while(gr.newRecord()){
if(gr.state==6){
closedchild +=1;
}
}
if(closedchild!=countofchild){
gs.addErrorMessage("Please close all the child incidents");
current.setAbortAction(true);
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 05:19 AM
Hi Akshay,
Update your script as below
var closedchild=0;
var gr= new GlideRecord('incident');
gr.addQuery('parent_incident',current.sys_id);
gr.addQuery('state', '!=', '7'); //check backend value of closed
gr.query();
var countofchild= gr.getRowCount();
gs.addInfoMessage("child incidents which are not closed are" +countofchild );
if(gr.next())
{
gs.addErrorMessage("Please close all the child incidents");
current.setAbortAction(true);
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 05:19 AM
Hi Akshay,
Update your script as below
var closedchild=0;
var gr= new GlideRecord('incident');
gr.addQuery('parent_incident',current.sys_id);
gr.addQuery('state', '!=', '7'); //check backend value of closed
gr.query();
var countofchild= gr.getRowCount();
gs.addInfoMessage("child incidents which are not closed are" +countofchild );
if(gr.next())
{
gs.addErrorMessage("Please close all the child incidents");
current.setAbortAction(true);
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 05:23 AM
as how?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 05:24 AM
I updated now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 05:27 AM
hello
try this script
(function executeRule(current, previous /*null when async*/) {
var closedchild=0;
var gr= new GlideRecord('incident');
gr.addQuery('parent_incident',current.sys_id);
gr.addQuery('state','!=','close choice value') //replace with closed choice value
gr.query();
var countofchild= gr.getRowCount();
if(countofchild>0)
{
gs.addInfoMessage("child incidents which are not closed are" +countofchild );
}
else
{
current.state="resolved choice value"
}
})(current, previous);
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU