How to copy the last CTASK close code to Change request while close the CR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2025 07:26 PM - edited ‎04-14-2025 07:27 PM
For the change request, the last task is change review task and when someone closes this task then Change request will auto closed as workflow gets completed after this CTASK activity.
We want that when this last task gets closed at the same time the close notes of this task should be copied to Change request notes section.
Please suggest that how its possible
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2025 07:56 PM
you can handle the same in your workflow if you are using that.
Have a run script to query the CTASK with this CHG and pick the latest one, pick the notes and put in CHG
something like this
// Add your code here
var gr = new GlideRecord("change_task");
gr.orderByDesc('sys_created_on'); // pick the latest one
gr.addQuery("change_request", current.sys_id);
gr.setLimit(1);
gr.query();
if (gr.next()) {
current.close_notes = gr.close_notes;
current.update();
}
OR Another way
Have after update business rule on change_task with condition as Task closes
Use similar script above and check if the task which is getting closed is the last one, if yes then copy
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2025 04:41 AM
I have created after update BR but its not working.
I checked and found that when we are querying the change record, instead of change request SYS_ID its picking up the sys if of last change task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2025 04:51 AM
sorry this line is updated now
gr.addQuery("change_request", current.change_request);
Use the below and test
// Add your code here
var gr = new GlideRecord("change_task");
gr.orderByDesc('sys_created_on'); // pick the latest one
gr.addQuery("change_request", current.change_request);
gr.setLimit(1);
gr.query();
if (gr.next()) {
current.close_notes = gr.close_notes;
current.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2025 04:03 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader