Help with Fix Script for Reclassifying Business/Technical Services in CMDB

ronro2
Tera Contributor

Hello!

In servicenow there is a base table 'cmdb_ci_service' that 'cmdb_ci_service_business' and 'cmdb_ci_service_technical' inherit from.

Only 15 records out of 137 are visible with service classification = Technical Service, in the list view for Technical Service table (cmdb_ci_service_technical). The rest with the same classification are only visible in the cmdb_ci_service table list view. So you want to move all of these from cmdb_ci_service to cmdb_ci_service_technical so that they are all visible on cmdb_ci_service_technical.

My collegue said this could be fixed via a simple Fix Script that would reclassify all those that have 'service_classification'  'Business Service' and class 'cmdb_ci_service' to instead have class cmdb_ci_service_business while those that have 'Technical Service' and class cmdb_ci_service' to be reclassified as 'cmdb_ci_service_technical'. 

Keep in mind, in the base table (cmdb_ci_service), there is the 'sys_class_name' field/column which contains ​​values 'cmdb_ci_service_technical' and 'cmdb_ci_service_business' that the fix script could use to reclassify the rows.

But my Fix Script just is not working as no rows have been updated, have I missed anything else to go through? So here is my Fix Script: 

 

(function executeFixScript() {
    var gr = new GlideRecord('cmdb_ci_service');
    gr.addQuery('sys_class_name', 'cmdb_ci_service'); // Endast de som inte redan är klassificerade
    gr.query();

    var updatedCount = 0;

    while (gr.next()) {
        if (gr.service_classification == 'business_service') {
            gr.sys_class_name = 'cmdb_ci_service_business';
            gr.update();
            updatedCount++;
        } else if (gr.service_classification == 'technical_service') {
            gr.sys_class_name = 'cmdb_ci_service_technical';
            gr.update();
            updatedCount++;
        }
    }

    gs.print('Fix script klart. Uppdaterade poster: ' + updatedCount);
})();


Thankful for help and input! 

1 ACCEPTED SOLUTION

Hristo Ivanov
Kilo Sage

hey, the script didn't work cause you are using business_service here: 

gr.service_classification == 'business_service'

but checking the XML on my instance <service_classification>Business Service</service_classification>

View solution in original post

6 REPLIES 6

@Hristo Ivanov Now it works partly. For instance, out of 1900 records on the cmdb_ci_service with Service Classification 'Business Service' only 636 records have been moved to cmdb_ci_service_business and 0 out of around 180  records have been moved to cmdb_ci_service_technical. 

So weird. 

Check the value for Technical Service; you may be using something different. 

 

Could you mark my comment as correct and helpful if it helped you?