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

@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.

View solution in original post

9 REPLIES 9

Shree_G
Mega 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);
     }

 

Shree_G
Mega 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.

Nishant8
Tera 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

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;
    }