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

Shree_G
Kilo Sage

Hello @shabbir5 ,

 

Remove the "current.state=previous.state;" from code and try below  Before business rule:

 

When to run:

Shree_G_0-1744619878856.png

 

Advance :

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

 


If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.

Shree_G
Kilo Sage

Refresh the page if the updated state is shown. Sometimes due to cache it displace the other states but is not updated in the database in actual.


If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.

Nishant8
Giga Sage

Hello @shabbir5, Can you please verify whether BR is configured to run 'Before' 'Update'? If you have configured as stated, can you share the complete screenshot of Business Rule?

 

Regards,

Nishant

Jaspal Singh
Mega Patron
Mega Patron

Hi Nishant,

 

Can you try below.

    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);
action.setRedirectURL(current);
current.state=previous.state;
    }