---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# CMDBUtil - Global

# CMDBUtil - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 8 minutes to read

The CMDBUtil API provides utility methods for creating and managing
table relationships in the Configuration Management Database (CMDB) and managing CMDB baselines.

CMDBUtil is a JavaScript-accessible ScriptableObject. The CMDBUtil API has
dynamic and static methods. You access dynamic methods by creating a SNC.CMDBUtil object. You
access static methods by using SNC.CMDBUtil global object to call the methods.  
This example creates a CMDBUtil object.

    var cu = new SNC.CMDBUtil();
    cu.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset'));

This example calls a static method.

    var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer');

Use these methods to manage CMDB table relationships and
baselines.

## CMDBUtil - baselineProposedChangesApplyChanges(GlideRecord proposedChanges) {#ariaid-title2}

Applies proposed changes in a task_ci record that represent an update set for all CIs
associated with the task.
This is a dynamic method.
{#r_CMDBU-basePropChApCh_GR__table_tlm_ytc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| proposedChanges | GlideRecord | The collection of proposed changes in the change request (CHG). |
[Table 1. Parameters]

{#r_CMDBU-basePropChApCh_GR__table_tlm_ytc_3v} {#r_CMDBU-basePropChApCh_GR__table_ulm_ytc_3v__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 2. Returns]

{#r_CMDBU-basePropChApCh_GR__table_ulm_ytc_3v}  

    //Where current is a GlideRecord and action is the current UI action
    var base = new SNC.CMDBUtil();
    base.baselineProposedChangesApplyChanges(current);

## CMDBUtil - baselineProposedChangesGenDiff(GlideRecord current, String changeSet) {#ariaid-title3}

Generates the XML for proposed changes diff, and adds it to the corresponding task_ci
record.
This is a dynamic method.
{#r_CMDBU-basePropChGenDiff_GR_S__table_p2w_2tc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| current | GlideRecord | The GlideRecord that contains the collection of proposed changes. |
| changeSet | String | The sysid of the task_ci record that represents the change set to use. |
[Table 3. Parameters]

{#r_CMDBU-basePropChGenDiff_GR_S__table_p2w_2tc_3v} {#r_CMDBU-basePropChGenDiff_GR_S__table_q2w_2tc_3v__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 4. Returns]

{#r_CMDBU-basePropChGenDiff_GR_S__table_q2w_2tc_3v}  

    //Where current is a GlideRecord and action is the current UI action
    var base = new SNC.CMDBUtil();
    base.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset'));

## CMDBUtil - bootstrap(String dictFile) {#ariaid-title4}

Bootstraps the environment by creating the database, creating the system dictionary
table, and having the system dictionary table describe itself.
This is a static method.
{#r_CMDBU-bootstrap_S__table_nc2_gwc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| dictFile | String | The file name including path, of the dictionary to load. |
[Table 5. Parameters]

{#r_CMDBU-bootstrap_S__table_nc2_gwc_3v} {#r_CMDBU-bootstrap_S__table_oc2_gwc_3v__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 6. Returns]

{#r_CMDBU-bootstrap_S__table_oc2_gwc_3v}

## CMDBUtil - createCIRelationship(String tableName, String parent, String child, String
parentField, String childField) {#ariaid-title5}

Creates a CI relationship between fields.
{#r_CMDBU-createCIRel_S_S_S_S_O__table_a1b_4kc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Optional. The name of the relationship target table. Default: CI Relationship \[cmdb_rel_ci\] table. |
| parent | String | Sys_id of the parent CI record in the Configuration Items \[cmdb_ci\] table. |
| child | String | Sys_id of the child CI record in the Configuration Items \[cmdb_ci\] table. |
| parentField | String | The parent relationship label listed in the CI Relationship Type \[cmdb_rel_type\] table. |
| childField | String | The child relationship label listed in the CI Relationship Type \[cmdb_rel_type\] table. |
[Table 7. Parameters]

{#r_CMDBU-createCIRel_S_S_S_S_O__table_a1b_4kc_3v} {#r_CMDBU-createCIRel_S_S_S_S_O__table_b1b_4kc_3v__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the new record listed in the CI Relationship \[cmdb_rel_ci\] table. |
[Table 8. Returns]

{#r_CMDBU-createCIRel_S_S_S_S_O__table_b1b_4kc_3v}  
The following example shows how to create a CI relationship between the parent CI contains
field and the child CI contained_by field. The relationship is listed in the CI Relationship
\[cmdb_rel_ci\] table.

    var base = new SNC.CMDBUtil();
    base.createCIRelationship('<parent_ci_sys_id>', '<child_ci_sys_id>, 'Contains', 'Contained by');

## CMDBUtil - getAllChildrenOfAsCommaList(String baseTable) {#ariaid-title6}

Gets all the child tables of the specified table as a comma-separated list.
This is a static method.
{#r_CMDBU-getAllCOfAsCList_S__table_o2r_nvc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| baseTable | String | The base table name. |
[Table 9. Parameters]

{#r_CMDBU-getAllCOfAsCList_S__table_o2r_nvc_3v} {#r_CMDBU-getAllCOfAsCList_S__table_p2r_nvc_3v__entry__2}

| Type | Description |
|-|-|
| String | A comma-separated list of sys_ids of tables extending the base table. |
[Table 10. Returns]

{#r_CMDBU-getAllCOfAsCList_S__table_p2r_nvc_3v}  

    //Where cmdv_ci_computer is a table.
    var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer');
    gs.print(output);

## CMDBUtil - getCMDBViews() {#ariaid-title7}

Gets all the records in the CMDB View \[cmdb_view\] table.
This method is dynamic.
{#r_CMDBU-getCMDBViews__table_gww_xwc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#r_CMDBU-getCMDBViews__table_gww_xwc_3v} {#r_CMDBU-getCMDBViews__table_hww_xwc_3v__entry__2}

| Type | Description |
|-|-|
| Array | List of the records in the CMDB View \[cmdb_view\] table. |
[Table 12. Returns]

{#r_CMDBU-getCMDBViews__table_hww_xwc_3v}  
The following example shows how to list the CMDB views.

    var util = new SNC.CMDBUtil(); 
    var cmdbViews = util.getCMDBViews();
    gs.info(cmdbViews);

    // Note that the output in the example is type: java.util.ArrayList
    // To convert to JS Array, use ArrayUtils (add these lines preceding gs.info):
    // var arrUtil = new global.ArrayUtil();
    // var arrViews = arrUtil.convertArray(cmdbViews);

Output:

    [View 3, View 1, View 2, Another view]

## CMDBUtil - getTables0(String tableName) {#ariaid-title8}

Gets a list of all the parents of a table.
This method is a static method.
{#r_CMDBU-getTables_S__table_qhg_bvc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | The table name. |
[Table 13. Parameters]

{#r_CMDBU-getTables_S__table_qhg_bvc_3v} {#r_CMDBU-getTables_S__table_rhg_bvc_3v__entry__2}

| Type | Description |
|-|-|
| Array | List of tables that are parents of the specified table. |
[Table 14. Returns]

{#r_CMDBU-getTables_S__table_rhg_bvc_3v}  
The following example shows how to list the parent tables of the Server \[cmdb_ci_server\]
table.

    var gr = new GlideRecord('incident');

    // Querying the incident table
    gr.addQuery('number','INC0000005'); 
    gr.query();


    if(gr.next()){
      // Find the list of parent tables for Configuration item field of this Incident
      var ciParent = SNC.CMDBUtil.getTables0(gr.cmdb_ci.sys_class_name); 
      gs.print("Parent Tables for the Configuration Item '" + gr.cmdb_ci.name + "' belonging to the CMDB Class '"+ gr.cmdb_ci.sys_class_name+ "' are: \n" + ciParent);
    }

Output:

    Parent Tables for the Configuration Item 'ApplicationServerPeopleSoft' belonging to the CMDB Class 'cmdb_ci_server' are: 
    [cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci, cmdb]

## CMDBUtil - isExcludedFromBR(String className) {#ariaid-title9}

Determines whether a CI class is defined in the Business Rule Exclusion Lists
\[cmdb_business_rule_exclusions\] table. Use this method in an advanced condition to prevent a
business rule from executing on excluded CI classes.
For example, the Create Asset on insert business rule uses this method in the advanced
condition to prevent the rule from creating assets for CI classes such as cmdb_ci_qualifier,
cmdb_ci_endpoint, cmdb_ci_storage_volume, and cmdb_ci_vcenter_datastore_disk. Define classes
for exclusion in the Business Rule Exclusion Lists \[cmdb_business_rule_exclusions\]
table.
{#CMDBU-isExcludedFromBR_S__table_bft_dgv_g2b__entry__3}

| Name | Type | Description |
|-|-|-|
| className | String | Name of the class to check for exclusion. |
[Table 15. Parameters]

{#CMDBU-isExcludedFromBR_S__table_bft_dgv_g2b} {#CMDBU-isExcludedFromBR_S__table_cft_dgv_g2b__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the class is defined in the Business Rule Exclusion Lists \[cmdb_business_rule_exclusions\] table; otherwise, false. |
[Table 16. Returns]

{#CMDBU-isExcludedFromBR_S__table_cft_dgv_g2b}  

    //Returns true if the cmdb_ci_endpoint class is defined 
    //in the Business Rule Exclusion Lists table
    var exclusion = SNC.CMDBUtil.isExcludedFromBR("cmdb_ci_endpoint");

    //Advanced condition that prevents business rules from executing on 
    //classes in the Business Rule Exclusion Lists table
    (!SNC.CMDBUtil.isExcludedFromBR(current.getTableName()))

## CMDBUtil - processCIChange(GlideRecord event, GlideRecord target) {#ariaid-title10}

Wraps the call to RelationshipEventProcessor(), which processes any
changes to CI relationships.
This is a dynamic method.
{#r_CMDBU-processCIChange_GR_GR__table_t5p_xhc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| event | GlideRecord | The event record. |
| target | GlideRecord | The target record. |
[Table 17. Parameters]

{#r_CMDBU-processCIChange_GR_GR__table_t5p_xhc_3v} {#r_CMDBU-processCIChange_GR_GR__table_u5p_xhc_3v__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 18. Returns]

{#r_CMDBU-processCIChange_GR_GR__table_u5p_xhc_3v}

## CMDBUtil - processRelChange(GlideRecord event, GlideRecord current, String relType, String
triplet) {#ariaid-title11}

Wraps the call to RelationshipEventProcessor(), which processes any
changes to CI relationships, with the specified type and triplet.
This is a dynamic method.
{#r_CMDBU-procRelChange_GR_GR_S_S__table_iwz_njc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| event | GlideRecord | The event record |
| current | GlideRecord | The current record, which is either the relation record or a user record if the current process is a deletion. |
| relType | String | The type of relation that changed. |
| triplet | String | The child, parent, and class name from the relation that changed. |
[Table 19. Parameters]

{#r_CMDBU-procRelChange_GR_GR_S_S__table_iwz_njc_3v} {#r_CMDBU-procRelChange_GR_GR_S_S__table_jwz_njc_3v__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 20. Returns]

{#r_CMDBU-procRelChange_GR_GR_S_S__table_jwz_njc_3v}

## CMDBUtil - removeCIRelationship(String tableName, String parentField, String childField,
String parentDesc, Object childDesc) {#ariaid-title12}

Deletes the specified CI relationship.
This is a dynamic method.
{#r_CMDBU-removeCIRel_S_S_S_S_O__table_a1b_4kc_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Optional. Table name Default: CI Relationship \[cmdb_rel_ci\] table |
| parentField | String | Parent field |
| childField | String | Child field |
| parentDesc | String | Parent relationship descriptor |
| childDesc | Object | Child relationship descriptor |
[Table 21. Parameters]

{#r_CMDBU-removeCIRel_S_S_S_S_O__table_a1b_4kc_3v} {#r_CMDBU-removeCIRel_S_S_S_S_O__table_jbs_nsc_3v__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 22. Returns]

{#r_CMDBU-removeCIRel_S_S_S_S_O__table_jbs_nsc_3v}  
This code example shows how to remove every relation type 'Depends on::Used by' for the
specified parent.

    var cu = new SNC.CMDBUtil();
    var parentSysID = '27d18f6fc0a8000b00ad14d4929d1b45';
    var parentDesc = 'Depends on';
    var childDesc = 'Used by'
     
    // Get records with parent equal parentSysID
    var relation = new GlideRecord('cmdb_rel_ci');
    relation.addQuery('parent', parentSysID);
    relation.query();
    while(relation.next()){
        // Remove every relation of type: 'Depends on::Used by' for the parent
        // If the relation type does not exist, it inserts this relation type into [cmdb_rel_type].
        cu.removeCIRelationship('cmdb_rel_ci', parentSysID, relation.child.getValue('sys_id'), parentDesc, childDesc)
    }

## CMDBUtil - reParentTable(String table, String oldParent, String newParent) {#ariaid-title13}

Changes the parent of the given table to the new parent.
{#r_CMDBU-reParentTable_S_S_S__table_gdq_m5c_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| table | String | The table to re-parent. |
| oldParent | String | The old parent. |
| newParent | String | The new parent. |
[Table 23. Parameters]

{#r_CMDBU-reParentTable_S_S_S__table_gdq_m5c_3v} {#r_CMDBU-reParentTable_S_S_S__table_hdq_m5c_3v__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates if the parent change is successful. Valid values: * true: Parent change was successful. * false: Parent change wasn't successful. {#r_CMDBU-reParentTable_S_S_S__ul_n3j_mn2_qrb} |
[Table 24. Returns]

{#r_CMDBU-reParentTable_S_S_S__table_hdq_m5c_3v}  
To recreate the following example, use the code provided to create a custom table. Next
create a record and check it in the task table. The custom table created extends from the
Task table, which means it has successfully re-parented. The code isn't intended to be
directly used via copy and paste. To show output, the custom table was created before
running the code.

    /*
      Before running the code in the background Script Make Sure 'Record For Rollback' is unchecked.

      This API CMDBUtil.reParentTable changes the parent of the table but will not allow the OOB tables to change the parent it works only in the custom table. Hence this script contains the creation of the custom table.
      API CMDBUtil.reParentTable has 3 parameters (Table, Old Parent , New Parent);
      We can make the Parent as Null as well by using this (Table, Old Parent, '');

      The code in this example shows how to create a custom table without any extension.
      Then creating a record and then again creating a record and checking in the task table after it gets extended to the task table.

      If the code returns false means the record is not present in the task table as it is not extended. It returns true only when the record is found in the task table after the table is extended.

    */

    /* Run the following code to create the custom table without an extension
    createCustomTable('u_custom_table','Custom Table'); // Creating a custom Table (don't create if you have one)
    var CreatedRecord = CreateCustomRecord('u_custom_table'); // Creating a record in the custom table
    gs.print(CheckRecord('u_custom_table'));  // Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)

    var getParentTables = new SNC.CMDBUtil.reParentTable('u_custom_table','','task'); // Extending the custom table to task table . This Works only when the table is extendable
    var CreatedRecordAfter = CreateCustomRecord('u_custom_table'); // Creating a record in the custom table
    gs.print(CheckRecord('u_custom_table'));  // Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
    */

    // If the custom Table is already created, run this. (Do not run these 4 lines when creating the table)
    gs.print(CheckRecord('u_custom_table')); //Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
    var getParentTables = new SNC.CMDBUtil.reParentTable('u_custom_table','','task'); //Extending the custom table to task table . This Works only when the table is extendable
    var CreatedRecordAfter = CreateCustomRecord('u_custom_table'); //Creating a record in the custom table
    gs.print(CheckRecord('u_custom_table'));  //Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)


    function createCustomTable(Name, Label)
    {
      var customTable = new GlideRecord('sys_db_object');
      customTable.initialize();
      customTable.name=  Name ;
      customTable.label= Label ;
      customTable.is_extendable= true;
      customTable.insert();
    }

    function CreateCustomRecord(customTableName)
    {
      var customTable = new GlideRecord(customTableName);
      customTable.initialize();
      return customTable.insert();
    }

    function CheckRecord(customTableName)
    {
      var task =new GlideRecord('task');
      task.addQuery('sys_class_name', customTableName);
      task.query();

      if(task.next())
      {
        return true;
      }

      return false;
    }

Output:

    *** Script: true
    *** Script: true


