Need assistance on Br rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 11:31 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 12:01 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 12:09 AM
@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();
}
}