Add new lifecycle stage fields to all CI and Asset forms

ruebenashto
Mega Guru

Hi Guys,

 

Is there a way to add the new LifeCycle in bulk to all CI/Asset table forms rather than opening one by one, likewise for removing the old ones(though currently doing this one through UI Policy).

Thank you.

1 ACCEPTED SOLUTION

ruebenashto
Mega Guru

I've now found a solution to this issue - therefore reposting to help those that have to add/remove fields in bulk.

Run the below background script:

var gr = new GlideRecord('sys_ui_element');
gr.addQuery('element', 'install_status');
gr.query();
while (gr.next()) {
    var existing = new GlideRecord('sys_ui_element');
    existing.addQuery('element', 'life_cycle_stage');
    existing.addQuery('sys_ui_section', gr.sys_ui_section);
    existing.setLimit('1');
    existing.query();
    if (existing.hasNext()) {
        gs.print(
            'Deleting install_status element ' + gr.sys_id +
            ' (life_cycle_stage already exists in section ' +
            gr.sys_ui_section + ')'
        );
        gr.deleteRecord();
        continue;
    }
    gr.element = 'life_cycle_stage';
    gr.update();
    gs.print('Renamed element: ' + gr.sys_id);
}
This will look up all the sections that contain the 'install_status' field and update it to the 'life_cycle_stage' field. This means the legacy field is swapped out for the life cycle field. Once this has ran, amend the script and change the 'Install_status' fields to 'operational_status' field. and swap 'life_cycle_stage' to ''life_cycle_stage_status'. (can probably combine in same script but I made this from scratch and was too much effort!).
Once this has done, you will need to remove the life_cycle_stage/life_cycle_stage_status field from the cmdb_ci summary section as else there will be duplicate fields across the tables. To do this, navigate to 'sys_ui_section' where:

Table = Configuration Item [cmdb_ci]

View = Explore Ci

Caption = Summary
And delete the life_cycle_stage/life_cycle_stage_status element in related list.

You may have to wait some time for this to work - I would recommend cls.

Let me know if anyone has any questions and please mark as helpful is useful.

View solution in original post

5 REPLIES 5

Mathew Hillyard
Giga Sage

Hi @ruebenashto 

I'm not aware of anything that automatically adds Lifecycle fields to all CI and Asset tables. There are many different forms and form layouts, so even if it were possible to apply a form field to all classes, you would still need to go into Form Builder for each form and locate these fields appropriately. Given that one of the main benefits of lifecycles is consistent values I believe it is more important in list views and reporting so you can group and report appropriately.

 

Some classes already have life cycle fields (e.g. Business Application) but many core CMDB tables do not - some don't even have any of the State fields OOTB.

 

I hope this helps!
Mat

ruebenashto
Mega Guru

I've now found a solution to this issue - therefore reposting to help those that have to add/remove fields in bulk.

 

Run the below background script:

 

var gr = new GlideRecord('sys_ui_element');
gr.addQuery('element', 'install_status');
gr.query();

while (gr.next()) {

    // Check if life_cycle_stage already exists in the same ui section
    var existing = new GlideRecord('sys_ui_element');
    existing.addQuery('element', 'life_cycle_stage');
    existing.addQuery('sys_ui_section', gr.sys_ui_section);
    existing.setLimit(1);
    existing.query();

    if (existing.hasNext()) {
        // Target already exists → delete install_status element
        gs.print(
            'Deleting install_status element ' + gr.sys_id +
            ' (life_cycle_stage already exists in section ' +
            gr.sys_ui_section + ')'
        );
        gr.deleteRecord();
        continue;
    }

    // Otherwise, rename
    gr.element = 'life_cycle_stage';
    gr.update();

    gs.print('Renamed element: ' + gr.sys_id);
}
 
This will look up all the sections that contain the 'install_status' field and update it to the 'life_cycle_stage' field. This means the legacy field is swapped out for the life cycle field. Once this has ran, amend the script and change the 'Install_status' fields to 'operational_status' field. and swap 'life_cycle_stage' to ''life_cycle_stage_status'. (can probably combine in same script but I made this from scratch and was too much effort!).
Once this has done, you will need to remove the life_cycle_stage/life_cycle_stage_status field from the cmdb_ci summary section as else there will be duplicate fields across the tables. To do this, navigate to 'sys_ui_section' where:

Table = Configuration Item [cmdb_ci]

View = Explore Ci

Caption = Summary
And delete the life_cycle_stage/life_cycle_stage_status element in related list.

You may have to wait some time for this to work - I would recommend cls.

 

Let me know if anyone has any questions and please mark as helpful is useful.

Cheers.

ruebenashto
Mega Guru

I've now found a solution to this issue - therefore reposting to help those that have to add/remove fields in bulk.

Run the below background script:

var gr = new GlideRecord('sys_ui_element');
gr.addQuery('element', 'install_status');
gr.query();
while (gr.next()) {
    var existing = new GlideRecord('sys_ui_element');
    existing.addQuery('element', 'life_cycle_stage');
    existing.addQuery('sys_ui_section', gr.sys_ui_section);
    existing.setLimit('1');
    existing.query();
    if (existing.hasNext()) {
        gs.print(
            'Deleting install_status element ' + gr.sys_id +
            ' (life_cycle_stage already exists in section ' +
            gr.sys_ui_section + ')'
        );
        gr.deleteRecord();
        continue;
    }
    gr.element = 'life_cycle_stage';
    gr.update();
    gs.print('Renamed element: ' + gr.sys_id);
}
This will look up all the sections that contain the 'install_status' field and update it to the 'life_cycle_stage' field. This means the legacy field is swapped out for the life cycle field. Once this has ran, amend the script and change the 'Install_status' fields to 'operational_status' field. and swap 'life_cycle_stage' to ''life_cycle_stage_status'. (can probably combine in same script but I made this from scratch and was too much effort!).
Once this has done, you will need to remove the life_cycle_stage/life_cycle_stage_status field from the cmdb_ci summary section as else there will be duplicate fields across the tables. To do this, navigate to 'sys_ui_section' where:

Table = Configuration Item [cmdb_ci]

View = Explore Ci

Caption = Summary
And delete the life_cycle_stage/life_cycle_stage_status element in related list.

You may have to wait some time for this to work - I would recommend cls.

Let me know if anyone has any questions and please mark as helpful is useful.

Cheers.

ruebenashto
Mega Guru

I've now found a solution to this issue - therefore reposting to help those that have to add/remove fields in bulk.

Run the below background script:

var gr = new GlideRecord('sys_ui_element');
gr.addQuery('element', 'install_status');
gr.query();
while (gr.next()) {
    var existing = new GlideRecord('sys_ui_element');
    existing.addQuery('element', 'life_cycle_stage');
    existing.addQuery('sys_ui_section', gr.sys_ui_section);
    existing.setLimit('1');
    existing.query();
    if (existing.hasNext()) {
        gs.print(
            'Deleting install_status element ' + gr.sys_id +
            ' (life_cycle_stage already exists in section ' +
            gr.sys_ui_section + ')'
        );
        gr.deleteRecord();
        continue;
    }
    gr.element = 'life_cycle_stage';
    gr.update();
    gs.print('Renamed element: ' + gr.sys_id);
}
This will look up all the sections that contain the 'install_status' field and update it to the 'life_cycle_stage' field. This means the legacy field is swapped out for the life cycle field. Once this has ran, amend the script and change the 'Install_status' fields to 'operational_status' field. and swap 'life_cycle_stage' to ''life_cycle_stage_status'. (can probably combine in same script but I made this from scratch and was too much effort!).
Once this has done, you will need to remove the life_cycle_stage/life_cycle_stage_status field from the cmdb_ci summary section as else there will be duplicate fields across the tables. To do this, navigate to 'sys_ui_section' where:

Table = Configuration Item [cmdb_ci]

View = Explore Ci

Caption = Summary
And delete the life_cycle_stage/life_cycle_stage_status element in related list.

You may have to wait some time for this to work - I would recommend cls.

Let me know if anyone has any questions and please mark as helpful is useful.