How to reclassify a CI from one class to another and preserve all the custom attributes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi,
So we have a custom table called Robot process (u_cmdb_ci_robot_process) and then we now have an OOB table called Base robot (cmdb_ci_base_rpa_robot).
They want everything moved from custom to the OOB table which means reclassifying everything and also preserving the data. I have already come up with a couple of solutions which are working for this requirement, but the ask is to make something scalable and reusable since the CMDB is highly customised and they want to go back to OOB as much as they can for a lot of classes.
My solution 1:
- take the excel of the custom table which includes all the fields and the sys ID and save it
- use a fix script to reclassify everything. So the fix script would go to the custom table, look at the field sys_class_name and change it to base robot and that will move all the records and OOB fields across too.
- create a staging table and have a transform map with field mappings of custom to OOB. Load in the saved excel and the custom fields are preserved in the new class too.
I have tested this and it works fine (though I have not made the fix script yet to automate the reclassification and am only testing on a few records)
Solution 2:
- Create a fix script which also preserves the custom fields, then reclassifies and then maps the custom field to the new fields. Essentially the same thing as the transform map, but more code heavy. Here is the fix script below and that again is also working fine
var grRobots = new GlideRecord('u_cmdb_ci_robot_process');
grRobots.setWorkflow(false);
grRobots.autoSysFields(false);
//target testing using sys id of 1 record at a time
grRobots.addQuery('sys_id', 'a6d5f9cadb7ec8d0960b77d33c961947');
grRobots.query();
while (grRobots.next()){
var values = {}; //storing values before class change
values.u_id = grRobots.getValue('u_id');
values.managed_by = grRobots.getValue('managed_by');
values.supported_by = grRobots.getValue('supported_by');
values.u_business_owner = grRobots.getValue('u_business_owner');
values.u_owning_business_unit = grRobots.getValue('u_owning_business_unit');
values.u_category = grRobots.getValue('u_category');
values.u_subcategory = grRobots.getValue('u_subcategory');
var sysId = grRobots.sys_id;
//changing the class
grRobots.sys_class_name = 'cmdb_ci_base_rpa_robot';
grRobots.update();
var newCI = new GlideRecord('cmdb_ci_base_rpa_robot');
if (newCI.get(sysId)){
//applying the mappings
newCI.pid = values.u_id;
newCI.owned_by = values.managed_by;
newCI.managed_by = values.supported_by;
newCI.supported_by = values.u_business_owner;
newCI.department = values.u_owning_business_unit;
newCI.category = values.u_category;
newCI.subcategory = values.u_subcategory;
newCI.update();
}
gs.info('Migrated CI: ' + newCI.name);
}
The fix script seems reusable, in that you wouldn't have to start from scratch but you would have to change a lot of the lines to fit each case so is there a solution where this can be done but its scalable and reusable for other classes?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
So, it's more on the knowledge side with no open questions. If there are no open questions, please add the prefix -Knowledge/Blog.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************

