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

J Siva
Tera Sage

Hi @ronro2 

You can manually upgrade (reclassify) the CI class without using any scripts:

  1. Navigate to the "cmdb_ci_service" table and filter the CI that you want to upgrade.

  2. In the list view, double-click on the "class" field and select the appropriate child class.

Note: You can use Shift + Down Arrow to select multiple records and update them simultaneously.

JSiva_0-1749022818544.png

 

Regards,
Siva

 

ronro2
Tera Contributor

@J Siva for some reason there is only one value for records when they're either "Technical Service" or "Business Service" even though I'm in the cmdb_ci_service base table: 

ronro2_0-1749024182043.png

 

@ronro2 As i mentioned earlier, go to cmdb_ci_service table and from the list view try to update the "Class" as technical service.

JSiva_0-1749025707153.png

 

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>