- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 11:25 PM
Hi, I'm struggling to compile a Business Rule script for a scenario I need. When I have multiple change tasks, if I close/cancel one of them I need to then auto close all of the others within the change request as well, with a specific reason code that is showing in a drop down list of a custom field.
So for example, I have 4 change tasks called:
Implement change
Inform CAB
Restrict capabilities
Control output
If within the 'Implement Change' task I close or cancel it, it should auto close the other three and select a closure code from a drop down field list that Ive created as a custom field.
I know how to auto close tasks if the change request is cancelled using a BR with a glide record and referring to the state record reference, so I presume its something similar?
I'd like to know how to set this please...
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 05:15 PM
Hello Simon,
To work on this, please write a Business Rule with Before and Update checked, select the advanced option and give condition in when to Run as " State changes to Closed" or as per the requirement.
In the advanced tab, write the following code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('change_request');
gr.addQuery('number',current.change_request);
gr.query();
while(gr.next()){
gr.setValue('state',3); //3 is the state for closed in my instance
gr.update();
}
var gs = new GlideRecord('change_task');
gs.addQuery('change_request',current.change_request);
gs.query();
while(gs.next()){
gs.setValue('state',3); //3 is the state for closed in my instance
gs.update();
}
})(current, previous);
It should work, if not, please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 05:15 PM
Hello Simon,
To work on this, please write a Business Rule with Before and Update checked, select the advanced option and give condition in when to Run as " State changes to Closed" or as per the requirement.
In the advanced tab, write the following code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('change_request');
gr.addQuery('number',current.change_request);
gr.query();
while(gr.next()){
gr.setValue('state',3); //3 is the state for closed in my instance
gr.update();
}
var gs = new GlideRecord('change_task');
gs.addQuery('change_request',current.change_request);
gs.query();
while(gs.next()){
gs.setValue('state',3); //3 is the state for closed in my instance
gs.update();
}
})(current, previous);
It should work, if not, please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 11:28 PM
Hi Eash,
Yes this works and thanks . However one final piece to this jigsaw is that I need some fields set in those subsequent tasks if possible. There are two custom fields and I need the values set like this when that BR runs:
u_closure_type, 'Cancelled'
u_closure_type, 'Cancelled by Implement Task'
This needs to only happen for the subsequent change tasks, and not the initial one that was cancelled.
Is this possible too?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2020 12:43 PM
This looks like the exact solution I need - I have it running on thee Change_Request table but is not closing the tasks. Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 11:43 PM
I suppose, try to implement it in the second block of GlideRecord for Change Task table.
You can modify it like this,
var csys_id = current.sys_id;
var gs = new GlideRecord('change_task');
gs.addQuery('change_request',current.change_request);
gs.query();
while(gs.next()){
if(csys_id != gs.sys_id){
gs.setValue('state',4);
gs.update();
}
}
Please Mark all the answers correct if they help.