---
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


---

# CIData - Global

# CIData - Global {#ariaid-title1}

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

The CIData script include is a utility class that provides methods for working with configuration item (CI) data structures in JavaScript.

This script include requires the Discovery (com.snc.discovery.core) plugin. You can use it in any server-side Discovery script.

Instances of this class represent a CI (both its base record and any related lists), and the
provided methods allow loading from or storing both the base record and related lists.  
This class acts as a container for simple classes acting as maps of property name/value pairs. This class contains three kinds of such maps.

* A single map representing the base CI table entry (such as one row cmdb_ci_linux_server and its superclasses). You can retrieve this map using the [CIData - getData()](https://servicenow-prod.fluidtopics.net/uJLyGJ_G2kol8oGatRBBSQ#r_CIData-getData "Gets the data map in the base CI record.") method.
* Arrays of maps representing the instances of related lists, with each array representing a single related list and each element of such an array representing a single row of that related list. These arrays can be retrieved with the [CIData - getRelatedList(String table, String refField)](https://servicenow-prod.fluidtopics.net/uJLyGJ_G2kol8oGatRBBSQ#r_CIData-getRelatedList_S_S "Gets an array of maps of data in the given related list (to this CI).") method.
* Arrays of maps representing the instances of many-to-many tables, with each array representing a single many-to-many table and each element of such an array representing a single row of that many-to-many table. These arrays can be retrieved with the [CIData - getM2MTable(String table, String refField)](https://servicenow-prod.fluidtopics.net/uJLyGJ_G2kol8oGatRBBSQ#r_CIData-getM2MTable_S_S "Returns an array of data maps in the given many-to-many list (to this CI).") method.
{#c_CIDataAPI__ul_hhm_3n1_rt}

## CIData - CIData(String debugFlag) {#ariaid-title2}

Creates an instance of the CIData class.
{#r_CIData-CIData_S__table_sjx_wn1_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| debugFlag | String | Flag that indicates whether to enable debug logging. Valid values: * True: Debug logging is enabled. * False: Debug logging is not enabled. {#r_CIData-CIData_S__ul_z5w_m4p_ppb} |
[Table 1. Parameters]

{#r_CIData-CIData_S__table_sjx_wn1_rt}  
This example creates and adds a related list to the CIData object.

    var ciDataObj = new CIData();
    var rl = new CIRelatedList('cmdb_serial_number', 'cmdb_ci');
    var sr = {};
    sr['serial_number_type'] = "bios";
    sr['serial_number'] = "1BC5E4z89246";
    sr['valid'] =  "true";
    rl.addRec(sr);
    ciDataObj.addRelatedList(rl);

## CIData - addRelatedList(Array relatedList) {#ariaid-title3}

Adds the specified related list to this instance.
{#r_CIData-addRelatedList_A__table_zkf_mp1_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| relatedList | Array | Related list to add. |
[Table 2. Parameters]

{#r_CIData-addRelatedList_A__table_zkf_mp1_rt} {#r_CIData-addRelatedList_A__table_alf_mp1_rt__entry__2}

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

{#r_CIData-addRelatedList_A__table_alf_mp1_rt}  
This example creates and adds a related list to the CIData object.

    var ciDataObj = new CIData();
    var rl = new CIRelatedList('cmdb_serial_number', 'cmdb_ci');
    var sr = {};
    sr['serial_number_type'] = "bios";
    sr['serial_number'] = "1BC5E4z89246";
    sr['valid'] =  "true";
    rl.addRec(sr);
    ciDataObj.addRelatedList(rl);

## CIData - convertRelatedList(String sensor, String tableName, String refField, String
keyName) {#ariaid-title4}

Converts the specified related list to a related list in a given sensor.
{#r_CIData-convertRelList_S_S_S_S__table_ldt_by1_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| sensor | String | The sensor |
| tableName | String | The table name |
| refField | String | The reference field |
| keyName | String | The key name |
[Table 4. Parameters]

{#r_CIData-convertRelList_S_S_S_S__table_ldt_by1_rt} {#r_CIData-convertRelList_S_S_S_S__table_mdt_by1_rt__entry__2}

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

{#r_CIData-convertRelList_S_S_S_S__table_mdt_by1_rt}

## CIData - fromXML(String xml) {#ariaid-title5}

Initializes the current CIData instance from the specified XML string.
{#r_CIData-fromXML_S__table_mtf_hx1_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| xml | String | An XML string. |
[Table 6. Parameters]

{#r_CIData-fromXML_S__table_mtf_hx1_rt} {#r_CIData-fromXML_S__table_ntf_hx1_rt__entry__2}

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

{#r_CIData-fromXML_S__table_ntf_hx1_rt}  
The following example shows how to get test XML-formatted CI Data collected during
discovery.

    var xmlCIData = '<CIData><data><fld name="cpu_name">Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz</fld><fld name="host_name">ip-172-31-19-95</fld><fld name="kernel_release">3.10.0-1160.45.1.el7.x86_64</fld><fld name="os">Linux CentOS</fld></data></CIData>';

    var ciData = new CIData();

    ciData.fromXML(xmlCIData);
    gs.log(ciData);

Output:

    CIData instance:
      cpu_name: Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
      host_name: ip-172-31-19-95
      kernel_release: 3.10.0-1160.45.1.el7.x86_64
      os: Linux CentOS
    [object Object]

## CIData - getData() {#ariaid-title6}

Gets the data map in the base CI record.
{#r_CIData-getData__table_c3h_cp1_rt__entry__3}

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

{#r_CIData-getData__table_c3h_cp1_rt} {#r_CIData-getData__table_d3h_cp1_rt__entry__2}

| Type | Description |
|-|-|
| Object | The data map |
[Table 9. Returns]

{#r_CIData-getData__table_d3h_cp1_rt}

## CIData - getM2MTable(String table, String refField) {#ariaid-title7}

Returns an array of data maps in the given many-to-many list (to this CI).
{#r_CIData-getM2MTable_S_S__table_qzb_hv1_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| table | String | Name of the table containing the related list. In the case of a many-to-many list, this is the name of the many-to-many table, not the target table. |
| refField | String | Name of the field in the related list that refers to this CI. In the case of a many-to-many list, this is the name of the referring field in the many-to-many table, not in the target table. |
[Table 10. Parameters]

{#r_CIData-getM2MTable_S_S__table_qzb_hv1_rt} {#r_CIData-getM2MTable_S_S__table_rzb_hv1_rt__entry__2}

| Type | Description |
|-|-|
| Array | List of data maps in the given many-to-many list. The list is not in any particular order. If this is not a many-to-many list, returns an empty array. |
[Table 11. Returns]

{#r_CIData-getM2MTable_S_S__table_rzb_hv1_rt}  
This example shows how to get the many-to-many relationships for the installed_on field of
the cmdb_software_instance table.

    function () {
      //Instantiate a new CIData class object
      var cdta = new CIData();

      //Load the current data from a CI record.
      cdta.loadFromCI('b4fd7c8437201000deeabfc8bcbe5dc1');

      // Returns an Array of Objects (records) of a given M2M related list
      var records = cdta.getM2MTable('cmdb_software_instance', 'installed_on');

      gs.info(JSON.stringify(records, null, 4));

    })();

Output:

    [
      {
        "sys_id": "208983661b3330106cdf0f26624bcb4b",
        "software": "46c1ec3ca9fe198100beafe77332be9a",
        "sys_updated_on": "2021-11-16 18:32:35",
        "sys_created_on": "2021-11-16 18:32:35",
        "name": "3D Groove Playback Engine-*ANNIE-IBM",
        "installed_on": "b4fd7c8437201000deeabfc8bcbe5dc1"
      },
      {
        "sys_id": "288983661b3330106cdf0f26624bcb4a",
        "software": "0c43bc5fc61122750182c13269a7a3ef",
        "sys_updated_on": "2021-11-16 18:32:35",
        "sys_created_on": "2021-11-16 18:32:35",
        "name": ".NET SDK 2003-*ANNIE-IBM",
        "installed_on": "b4fd7c8437201000deeabfc8bcbe5dc1"
      }
    ]

## CIData - getRelatedList(String table, String refField) {#ariaid-title8}

Gets an array of maps of data in the given related list (to this CI).
The array is not in any particular order. In the case of a many-to-many list, this will be
an array of instances of the target table, not the many-to-many table. For example, given
'cmdb_software_instance' and 'installed_on' (a many-to-many table and the field that refers
to a CI), this method will return an array of maps representing cmdb_ci_spkg (the target
table) instances.
{#r_CIData-getRelatedList_S_S__table_rgy_451_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| table | String | Name of the table containing the related list. In the case of a many-to-many list, this is the name of the many-to-many table, not the target table. |
| refField | String | Name of the field in the related list that refers to this CI. In the case of a many-to-many list, this is the name of the referring field in the many-to-many table, not in the target table. |
[Table 12. Parameters]

{#r_CIData-getRelatedList_S_S__table_rgy_451_rt} {#r_CIData-getRelatedList_S_S__table_sgy_451_rt__entry__2}

| Type | Description |
|-|-|
| Array | An array of maps of data in the specified related list. |
[Table 13. Returns]

{#r_CIData-getRelatedList_S_S__table_sgy_451_rt}

## CIData - getRelatedListInstance(String table, String refField) {#ariaid-title9}

Returns the instance of CIRelatedList for the given list.
{#r_CIData-getRelatedListInst_S_S__table_aff_yv1_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| table | String | Name of the table containing the related list. In the case of a many-to-many list, this is the name of the many-to-many table, not the target table. |
| refField | String | Name of the field in the related list that refers to this CI. In the case of a many-to-many list, this is the name of the referring field in the many-to-many table, not in the target table. |
[Table 14. Parameters]

{#r_CIData-getRelatedListInst_S_S__table_aff_yv1_rt} {#r_CIData-getRelatedListInst_S_S__table_bff_yv1_rt__entry__2}

| Type | Description |
|-|-|
| Object | Instance of the `CIRelatedList` for the specified list. |
[Table 15. Returns]

{#r_CIData-getRelatedListInst_S_S__table_bff_yv1_rt}  
The following code example uses the getRelatedListInstance() method to
find the related list relationships to remove.

    removeAllRelatedList: function(ci_id) {
      var cdta = new CIData('false');
      cdta.init();
      cdta.loadFromCI(ci_id); // Get a Computer CI Instance
      var cirelatedlist = cdta.getRelatedListInstance('cmdb_rel_ci', 'parent'); // Get the CIRelatedList instance holding all relationships of the above CI.
      cirelatedlist.remove(); // Remove all the CI Relationships
    }

## CIData - init() {#ariaid-title10}

Initializes this instance in preparation for loading a new CI.
{#r_CIData-init__table_zc2_v41_rt__entry__3}

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

{#r_CIData-init__table_zc2_v41_rt} {#r_CIData-init__table_ad2_v41_rt__entry__2}

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

{#r_CIData-init__table_ad2_v41_rt}  

    var cdta = CIData('false');
    cdta.init();

## CIData - loadFromCI(String cmdb_ci) {#ariaid-title11}

Loads the current data from a specified sys_id.
{#r_CIData-loadFromCI_S__table_yst_mw1_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| cmdb_ci | String | The sys_id of the CI |
[Table 18. Parameters]

{#r_CIData-loadFromCI_S__table_yst_mw1_rt} {#r_CIData-loadFromCI_S__table_zst_mw1_rt__entry__2}

| Type | Description |
|-|-|
| Object | The current data from the specified CI. |
[Table 19. Returns]

{#r_CIData-loadFromCI_S__table_zst_mw1_rt}  

    var cdta = CIData('false');
    cdta.init();
    cdta.loadFromCI('ccaf9c0a8016400b98a06818d57c7');

## CIData - toString() {#ariaid-title12}

Converts the name of this CIData instance to a string.
{#r_CIData-toString__table_t31_px1_rt__entry__3}

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

{#r_CIData-toString__table_t31_px1_rt} {#r_CIData-toString__table_u31_px1_rt__entry__2}

| Type | Description |
|-|-|
| String | Name of the instance |
[Table 21. Returns]

{#r_CIData-toString__table_u31_px1_rt}  
This example loads the CIData from the current CI and converts this new CIData instance
into string format.

    var cidata = new CIData(); // Instantiate a new CIData class object
    cidata.loadFromCI('0c43b0f5c6112275019abd2bb3dcd78f'); // Load the current data from a CI record. Use sys_id or ci name.
    cidata.toString(); // Convert the name of this CIData instance to a string.
    gs.info(cidata); // Display name value pairs of the current CI

Output:

    CIData instance:
      sys_id: 0c43b0f5c6112275019abd2bb3dcd78f
      operational_status: 1
      os_service_pack: Service Pack 1
      cpu_manufacturer: 0c43b088c6112275011a4bd46a4e6cc4
      sys_updated_on: 2022-01-11 07:44:05
      discovery_source: Other Automated
      ram: 503
      cpu_speed: 1993
      sys_domain_path: /
      disk_space: 37.26
      cost_center: d9d07bddc0a80a647cf932056ed24652
      assigned: 2020-08-31 08:00:00
      cd_speed: -1
      can_print: 0
      sys_class_name: cmdb_ci_computer
      manufacturer: add7b97737e3100044e0bfc8bcbe5d96
      cpu_count: 1
      vendor: adb3d8ce37413000158bbfc8bcbe5d15
      assigned_to: 5137153cc611227c000bbd1bd8cd2007
      os_version: 5.1.2600
      cd_rom: 0
      unverified: 0
      asset: aac1ba8837f3100044e0bfc8bcbe5d3b
      skip_sync: 0
      sys_created_on: 2005-05-24 01:14:19
      sys_domain: global
      cpu_type: GenuineIntel
      install_date: 2020-05-19 07:00:00
      asset_tag: P1000143
      install_status: 1
      name: ANDREWDWXP
      subcategory: Computer
      virtual: 0
      sys_class_path: /!!/!2/!(
      company: 31bea3d53790200044e0bfc8bcbe5dec
      department: 221f3db5c6112284009f4becd3039cc9
      cost: 1299.99
      os: Windows XP Professional
      attestation_status: Not Yet Reviewed
      monitor: 0
      ip_address: 195.11.1.1
      cost_cc: USD
      location: db9a923c0a0a0a6501068d6eaec25ee0
      category: Hardware
      fault_count: 0
    [object Object]

## CIData - toXML() {#ariaid-title13}

Returns an XML string containing a serialized version of this instance (including any
related lists).
{#r_CIData-toXML__table_trp_xw1_rt__entry__3}

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

{#r_CIData-toXML__table_trp_xw1_rt} {#r_CIData-toXML__table_urp_xw1_rt__entry__2}

| Type | Description |
|-|-|
| String | The XML string containing a serialized version of this instance and any related lists. |
[Table 23. Returns]

{#r_CIData-toXML__table_urp_xw1_rt}  

    var cdta = CIData();
    cdta.toXML();


