Need assistance on Br rule

Pawan Kumar Rai
Tera Contributor

There is a "caused_by" field in INC form. When that field is having closed change chg. Then that change should reopen & go in review stage.

I tried with the below BR rule but not working. Can anyone pls correct me?

table: inc

when to apply: caused_by is not empty or when it changes.

type: after...inserted/updated

 

script:

 

 if (current.caused_by.change_request.state == 7) //if there is closed change in caused_by field

    {

    var chg = current.caused_by;                              //taking change value

     var change = new GlideRecord('change_request');

     change.addQuery('sys_id', chg);                       //if its matched then make it reopen

     change.query();

       change.state = '0';

       change.close_code = 'unsuccessful';

       change.update();

     }

6 REPLIES 6

Ahmmed Ali
Mega Sage

Hello @Pawan Kumar Rai 

 

Couple of inputs:

A change request should not be reopened after closing, you need to have a new change request created along with an incident. But again this depends on your Org practice.

 

Now coming to your issue, try below script:

 

if (current.caused_by.change_request.state == 7) //if there is closed change in caused_by field

    var chg = current.caused_by;                              //taking change value

     var change = new GlideRecord('change_request');

     change.addQuery('sys_id', current.caused_by.toString());   //if its matched then make it reopen

    

     change.query();

if(change.next()){

       change.state = '0';

       change.close_code = 'unsuccessful';

       change.update();

}

}

 

You are missing next() function to move to retrieved record in GlideRecord object.

 

Thank you,

Ali

 

 

 

 

    

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

But there should be curly braces in first if loop {}..? where its checking ==7

when tried to put braces...its not working

first if loop is not having curly braces...by adding its not working.

tried with your script, its working for all change stage 

Anirudh Pathak
Mega Sage

Hi @Pawan Kumar Rai,

I think you are missing this line -

if(change.next()) {
}

Please try updated code given below  - 

 if (current.caused_by.change_request.state == 7) //if there is closed change in caused_by field

    {

    var chg = current.caused_by;                              //taking change value

     var change = new GlideRecord('change_request');

     change.addQuery('sys_id', chg);                       //if its matched then make it reopen
  

     change.query();
     if(change.next()) {
       change.state = '0';

       change.close_code = 'unsuccessful';

       change.update();

     }
}