reassigning ticket categories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 01:37 PM
We added and removed "categories" and would like to reclassify some past tickets to the new categories without doing it manually due to the volume. Can this be done and if so, how? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 04:07 PM
You can achieve this using a GlideRecord Operations. Example below on Incident Table:
var grIncident = new GlideRecord("incident");
grIncident.addEncodedQuery('category=the_category_needed_to_be_updated');
grIncident.query();
while (grIncident.next()) {
grIncident.setWorkflow(false);
grIncident.autoSysFields(false);
grIncident.category = 'new_category_value';
grIncident.update();
}
grIncident.setWorkflow(false);
This function is used to disable the workflow for a specific record (in this case, an "incident"). By default, workflows are triggered when records are created or updated in ServiceNow. When you set the workflow to false, you are telling the system not to trigger any workflow for that particular record during the transaction.
grIncident.autoSysFields(false);
This function disables the automatic setting of system fields for the grIncident record.
In ServiceNow, system fields such as sys_created_on, sys_updated_on, sys_created_by, and sys_updated_by are automatically managed by the platform. When you create or update a record, ServiceNow automatically updates these fields to reflect the creation and modification timestamps and the users who created or updated the record.
By calling grIncident.autoSysFields(false);, you are telling the system not to automatically update these system fields when the record is modified or created in the script.
Depending on your requirements, you can adjust the script. The 2 mentioned above functions are generally avoided and not recommended but I would admit that sometimes there is no escape from them. If you have reports/dashboards which run on data such as last time a ticket has been updated, then I would recommend to keep the second function (grIncident.autoSysFields(false);) as those fields will not get updated.
The first one (grIncident.setWorkflow(false);)should be used to avoid any notifications, workflow, SLA, ...
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 04:11 PM
Something to add: You can run the script as "Fix Script", you can setLimit before you query to update few records at first and monitor the results, if they are up to your expectations. You can then remove the limit by commenting or removing the line from the script.
var grIncident = new GlideRecord("incident");
grIncident.addEncodedQuery('category=the_category_needed_to_be_updated');
grIncident.setLimit(10) //Only 10 Records would be updated
grIncident.query();
while (grIncident.next()) {
grIncident.setWorkflow(false);
grIncident.autoSysFields(false);
grIncident.category = 'new_category_value';
grIncident.update();
}
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2025 06:23 AM
Thank you very much, I will take the time to digest this and I'm sure I will have questions. This is very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2025 05:50 AM
Thank you very much. This is very helpful. I need time to digest all of this and I'm sure I will have questions. Thanks!!!!