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

surajchacherkar
Mega Guru

Hi @Pawan Kumar Rai ,

 

try below code, it will work , you missed to add 

if(change.next()) {
}

Try below code:

 

if (current.caused_by && current.caused_by.change_request.state == 7) {
  var chg = current.caused_by; 
  var change = new GlideRecord('change_request');
  change.get(chg); // Use get() instead of addQuery() and query()
  if (change) { 
    change.state = '0'; // Set to review stage 
    change.close_code = 'unsuccessful'; // Clear close code
    change.update();
  }
}

 

 

 

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.
Thanks

Suraj

 

 

Sandeep Rajput
Tera Patron
Tera Patron

@Pawan Kumar Rai Here is the fixed 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();

       if(change.next()){

       change.state = '0';

       change.close_code = 'unsuccessful';

       change.update();

     }

     }