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-11-2024 11:42 PM
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
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 10:44 PM - edited ‎06-12-2024 10:47 PM
But there should be curly braces in first if loop {}..? where its checking ==7
when tried to put braces...its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2024 12:22 AM
first if loop is not having curly braces...by adding its not working.
tried with your script, its working for all change stage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 11:42 PM
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();
}
}