- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 07:58 AM
How to prepare a one-time fix script to migrate any change tasks for tickets in Draft, Assess from "SC-ETS-ABCD" to Change Owner group?
Note:
A change owner group is a dynamic group.
But the SC-ETS-ABCD is fixed and it will come to the task implementer group.
I have attempted to write the code, it is functioning, but the issue is, it is migrating the Task Implementer Group one at a time it is not processing in a batch. For multiple change tasks, the script needs to be executed multiple times.
Here is the code,
var chgtsk = new GlideRecord('change_task');
chgtsk.addEncodedQuery('active=true^parent.state=301^ORparent.state=302^u_task_implementer_group=07d39f9c1b556c5080452136ec4bcbc1');
chgtsk.query();
if(chgtsk.next()){
chgtsk.u_task_implementer_group = chgtsk.parent.assignment_group;
chgtsk.update();
}
Could you please help me to fix the issue?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 08:16 AM
Hi!
To migrate multiple change tasks for tickets in Draft, Assess from "SC-ETS-ABCD" to Change Owner group using a script in ServiceNow, you can modify the code to use a batch update. Here is an example script:
// Set the batch size var batchSize = 100; // Query for change tasks that need to be updated var chgtsk = new GlideRecord('change_task'); chgtsk.addEncodedQuery('active=true^parent.state=301^ORparent.state=302^u_task_implementer_group=07d39f9c1b556c5080452136ec4bcbc1'); chgtsk.query(); chgtsk.setLimit(batchSize); // Update each change task while (chgtsk.next()) { chgtsk.u_task_implementer_group = chgtsk.parent.assignment_group; chgtsk.update(); } // Continue querying and updating in batches until no more records are found while (chgtsk.hasNext()) { // Query for the next batch of change tasks chgtsk.next(); chgtsk.setLimit(batchSize); // Update each change task in the batch while (chgtsk.next()) { chgtsk.u_task_implementer_group = chgtsk.parent.assignment_group; chgtsk.update(); } }
This script uses a batch size of 100, which can be adjusted based on your environment and performance requirements.
Note: Please test this script in a non-production environment before executing it in a production environment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 08:16 AM
Hi!
To migrate multiple change tasks for tickets in Draft, Assess from "SC-ETS-ABCD" to Change Owner group using a script in ServiceNow, you can modify the code to use a batch update. Here is an example script:
// Set the batch size var batchSize = 100; // Query for change tasks that need to be updated var chgtsk = new GlideRecord('change_task'); chgtsk.addEncodedQuery('active=true^parent.state=301^ORparent.state=302^u_task_implementer_group=07d39f9c1b556c5080452136ec4bcbc1'); chgtsk.query(); chgtsk.setLimit(batchSize); // Update each change task while (chgtsk.next()) { chgtsk.u_task_implementer_group = chgtsk.parent.assignment_group; chgtsk.update(); } // Continue querying and updating in batches until no more records are found while (chgtsk.hasNext()) { // Query for the next batch of change tasks chgtsk.next(); chgtsk.setLimit(batchSize); // Update each change task in the batch while (chgtsk.next()) { chgtsk.u_task_implementer_group = chgtsk.parent.assignment_group; chgtsk.update(); } }
This script uses a batch size of 100, which can be adjusted based on your environment and performance requirements.
Note: Please test this script in a non-production environment before executing it in a production environment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 10:50 AM
Thanks a lot, Andrew, it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 02:23 AM
Glad i could help!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 08:17 AM
Hi @Kaushik Ghosh ,
Replace if with while it should work for multiple records.
Please run your code in lower environment first.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Harshal