setAbortAction is not working in before business rules

shabbir5
Tera Guru

Hi All,

 

I am using below code to check the child incident state before closing parent incident , but the code is not working , someone please check and suggest the code changes 

 

 
     var gr = new GlideRecord('incident');
    gr.addQuery('parent_incident', current.sys_id);
     gr.addQuery('stateNOT IN6,7');
    gr.query();
    if (gr.next()) {
       
       
    gs.addErrorMessage('please close child incidents before clsong parent incident');
    current.setAbortAction(true);
    current.state=previous.state;
    }

 

i am making the parent incidents state to resolved , instead of abort the state value is setting to resolved

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@shabbir5 

your business rule should be of type Before update

use this script with some minor change

     var gr = new GlideRecord('incident');
     gr.addQuery('parent_incident', current.sys_id);
     gr.addQuery('stateNOT IN6,7');
     gr.query();
     if (gr.hasNext()) {
         gs.addErrorMessage('please close child incidents before clsong parent incident');
         current.setAbortAction(true);
         current.state = previous.state;
     }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@shabbir5 

your business rule should be of type Before update

use this script with some minor change

     var gr = new GlideRecord('incident');
     gr.addQuery('parent_incident', current.sys_id);
     gr.addQuery('stateNOT IN6,7');
     gr.query();
     if (gr.hasNext()) {
         gs.addErrorMessage('please close child incidents before clsong parent incident');
         current.setAbortAction(true);
         current.state = previous.state;
     }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Thank you for your response , the script you suggested is not working , we are getting the error log but incident state is updating to "Resolved"

 

let me know if any changes required

 

Regards

Shabbir Shaik

@shabbir5 

share the BR configuration screenshots

did you check logs and see what came?

check which field populated parent? is it parent or parent_incident ?

try this

     var gr = new GlideRecord('incident');
     gr.addQuery('parent_incident', current.sys_id).addOrCondition('parent', current.sys_id);
     gr.addActiveQuery();
     gr.query();
     if (gr.hasNext()) {
         gs.addErrorMessage('please close child incidents before clsong parent incident');
         current.setAbortAction(true);
         current.state = previous.state;
     }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@shabbir5 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@shabbir5 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader