- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 11:39 AM
Trying to cancel a change when the change task gets canceled, it is not working below is the code
BR on change_task table, order 10 triggers when the status is closed canceled
var gr = new GlideRecord('change_request');
gr.addQuery('active',true);
gr.addQuery('number', current.parent);
gr.query();
while(gr.next()){
gr.state = '4';
gr.update();
}
I have seen a Set activity in the workflow which is making the change the progress to a further stage. But if I try to adjust the workflow to cancel the change if ctask is canceled some tasks are not getting created.
Any idea what is going wrong here.
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:06 PM - edited 08-26-2024 01:08 PM
Hello Shidhi,
current.parent returns the sys_id rather than the number. In your script, you have to use current.parent.number, instead. Also, there is no need to use a while loop, as change_task is associated to only one change_request :
var gr = new GlideRecord('change_request');
gr.addQuery('active',true);
gr.addQuery('number', current.parent.number);
gr.setLimit(1); // for performance.
gr.query();
if(gr.next()){
gr.state = '4';
gr.update();
}
Best regards,
Hajar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:16 PM
@Shidhi your code looks correct. only Update gr.addQuery('number', current.parent); to gr.addQuery('number', current.parent.number); to correctly retrieve the number of the parent change request from the change task.
…………………………………………........................................................................................
Please Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 11:45 AM
Hi @Shidhi try now
var gr = new GlideRecord('change_request');
gr.addQuery('active',true);
gr.addQuery('sys_id', current.parent);
gr.query();
while(gr.next()){
gr.state = '4';
gr.update();
}
Thanks,
Harsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:06 PM - edited 08-26-2024 01:08 PM
Hello Shidhi,
current.parent returns the sys_id rather than the number. In your script, you have to use current.parent.number, instead. Also, there is no need to use a while loop, as change_task is associated to only one change_request :
var gr = new GlideRecord('change_request');
gr.addQuery('active',true);
gr.addQuery('number', current.parent.number);
gr.setLimit(1); // for performance.
gr.query();
if(gr.next()){
gr.state = '4';
gr.update();
}
Best regards,
Hajar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:16 PM
@Shidhi your code looks correct. only Update gr.addQuery('number', current.parent); to gr.addQuery('number', current.parent.number); to correctly retrieve the number of the parent change request from the change task.
…………………………………………........................................................................................
Please Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................