How to close changeTask(Ctask00001) if we close change request(Chg0001)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2017 02:09 AM
Hi Friends.
I am able to close 100's of Change requests by 'Scripts-background' using GlideRecord.
But most of the change requests has Ctasks associated with it.
can you please suggest me how to close ctask as well along with change requests.
My script to close Change
var chn = new GlideRecord('change_request');
chn.addQuery('number','IN','CHG0011111,CHG00222222');
chn.query();
while (chn.next()) {
chn.state=4;//Closed Incomplete
chn.update();
}
I am able to close change request but how to close Ctask as well associated with change.
Thank you very much in advance.
regards
Aarav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2017 02:14 AM
Hi,
If you still have change requests pending to be deactivated,
1) Please write a BR on change request table to close the task as soon as the change gets closed.
So once you close the change request through script, (make sure setworkflow false is not added there), it will automatically close the change task
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('change_task');
gr.addQuery('change_request',current.sys_id);
gr.query();
while(gr.next()){
gr.state=3; //for close complete
gr.update();
}
})(current, previous);
2) If you have already deactivated the change request and want just to deactivate the change task, then follow below script. ( use it in background script)
var chg= new GlideRecord('change_request');
chg.addQuery('state',4); //closed state
chg.query();
while(chg.query()){
var gr = new GlideRecord('change_task');
gr.addQuery('change_request',chg.sys_id);
gr.query();
while(gr.next()){
gr.state=3; //for close complete
gr.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2017 02:16 AM
something like this should help.
var changeTask = new GlideRecord('change_task');
changeTask.addQuery('change_request.number','IN','CHG0011111,CHG00222222');
changeTask.query();
if(changeTask.next()){
changeTask.state=4;
changeTask.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2017 02:53 AM
Aarav Aarav wrote:
Hi Friends.
I am able to close 100's of Change requests by 'Scripts-background' using GlideRecord.
But most of the change requests has Ctasks associated with it.
can you please suggest me how to close ctask as well along with change requests.
First question I'm going to ask is: why mass-close all of these? Shouldn't they have been closed by the change deployment?
Secondly, changes are generally closed when all change tasks are complete. Really, you want to look at closing those tasks so that the change is marked complete, rather than marking the change completed and hoping all child tasks close automatically.