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

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# CIRelatedList - Global

# CIRelatedList - Global {#ariaid-title1}

Release version: Australia  
Updated March 12, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes to read  
The CIRelatedList script include is a utility class that provides methods for working with configuration item (CI) related lists.

Each instance of this script include contains the details of a single list that is related to a particular CI. The details of this list and the contents of the list are included.

Use with any server-side discovery script.

## CIRelatedList - addRec(Object record) {#ariaid-title2}

Adds the specified record to the related list.
{#r_CIRL-addRec_S__table_bzv_mlh_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| record | Object | Each member in the object is a column name in the associated table. For example, if referencing the cmdb_serial_number table this value may contain something similar to the following: `{"serial_number_type":"bios","serial_number":"1BC5E4z89246","valid":"true"}` |
[Table 1. Parameters]

{#r_CIRL-addRec_S__table_bzv_mlh_rt} {#r_CIRL-addRec_S__table_czv_mlh_rt__entry__2}

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

{#r_CIRL-addRec_S__table_czv_mlh_rt}  
This example shows how to add a record to a CI related list.

    var ciDataObj = new CIData(); // Instantiate a new CIData class object

    // sys_id of the CI to which the related list is attached.
    var rl = new CIRelatedList('cmdb_serial_number', 'cmdb_ci','0c43b0f5c6112275019abd2bb3dcd78f','true');

    // Create an object and add the serial numbers
    var sr = {"serial_number_type":"bios","serial_number":"1BC5E4z89246","valid":"true"};
    rl.addRec(sr); // Add the related list. Sets the given records to the related list.
    ciDataObj.addRelatedList(rl); // Adding the related list to the cidata
    gs.info(JSON.stringify(rl, null, 4)); // Display the added related list

Output:

    {
      "GlideRecordUtil": {},
      "ignoreFields": {
        "sys_created_by": true,
        "sys_updated_by": true,
        "sys_mod_count": true
      },
      "records": [
        {
          "serial_number_type": "bios",
          "serial_number": "1BC5E4z89246",
          "valid": "true"
        }
      ],
      "m2m_records": [],
      "table_name": "cmdb_serial_number",
      "field_name": "cmdb_ci",
      "cmdb_ci": "0c43b0f5c6112275019abd2bb3dcd78f",
      "debug_flag": "true",
      "isM2M": false,
      "target_table_name": null,
      "target_ref_field_name": null
    }

## CIRelatedList - addRecs(Array records) {#ariaid-title3}

Sets the given records to the related list.
{#r_CIRL-addRecs_S__table_itb_wlh_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| records | Array of Objects | Each object represents a record in the associated table. Each member in the object is a column name in that table. For example, if referencing the cmdb_serial_number table this value may contain something similar to the following: `[{"serial_number_type":"bios","serial_number":"1BC5E4z89246","valid":"true"},{"serial_number_type":"baseboard","serial_number":"w4z89246","valid":"true"}]` |
[Table 3. Parameters]

{#r_CIRL-addRecs_S__table_itb_wlh_rt} {#r_CIRL-addRecs_S__table_jtb_wlh_rt__entry__2}

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

{#r_CIRL-addRecs_S__table_jtb_wlh_rt}  
This example shows how to add multiple records to a CI related list.

    var ciDataObj = new CIData(); // Instantiate a new CIData class object

    // sys_id of the CI to which the related list is attached.
    var rl = new CIRelatedList('cmdb_serial_number', 'cmdb_ci','0c43b0f5c6112275019abd2bb3dcd78f','true');

    // Create an object and add the serial numbers
    var sr = [{"serial_number_type":"bios","serial_number":"1BC5E4z89246","valid":"true"},{"serial_number_type":"baseboard","serial_number":"w4z89246","valid":"true"}];

    rl.addRecs(sr); // Add the related list. Sets the given records to the related list.

    ciDataObj.addRelatedList(rl); // Adding the related list to the cidata
    gs.info(JSON.stringify(rl, null, 4)); // Display the added related list

Output:

    {
      "GlideRecordUtil": {},
      "ignoreFields": {
        "sys_created_by": true,
        "sys_updated_by": true,
        "sys_mod_count": true
      },
      "records": [
        {
          "serial_number_type": "bios",
          "serial_number": "1BC5E4z89246",
          "valid": "true"
        },
        {
          "serial_number_type": "baseboard",
          "serial_number": "w4z89246",
          "valid": "true"
        }
      ],
      "m2m_records": [],
      "table_name": "cmdb_serial_number",
      "field_name": "cmdb_ci",
      "cmdb_ci": "0c43b0f5c6112275019abd2bb3dcd78f",
      "debug_flag": "true",
      "isM2M": false,
      "target_table_name": null,
      "target_ref_field_name": null
    }

## CIRelatedList - appendXMLChildFld(String parent, String name, String datum) {#ariaid-title4}

Appends an XML child to a field.
{#r_CIRL-appendXMLChildFld_S_S_S__table_kvc_qph_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| parent | String | The parent element |
| name | String | The element name |
| datum | String | The data to append |
[Table 5. Parameters]

{#r_CIRL-appendXMLChildFld_S_S_S__table_kvc_qph_rt} {#r_CIRL-appendXMLChildFld_S_S_S__table_lvc_qph_rt__entry__2}

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

{#r_CIRL-appendXMLChildFld_S_S_S__table_lvc_qph_rt}

## CIRelatedList - appendXMLChildRecord(String parent, String name, String record) {#ariaid-title5}

Appends an XML child to a record.
{#r_CIRL-appendXMLChildRecord_S_S_S__table_v3n_2ph_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| parent | String | The parent element |
| name | String | The element name |
| record | String | The record |
[Table 7. Parameters]

{#r_CIRL-appendXMLChildRecord_S_S_S__table_v3n_2ph_rt} {#r_CIRL-appendXMLChildRecord_S_S_S__table_w3n_2ph_rt__entry__2}

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

{#r_CIRL-appendXMLChildRecord_S_S_S__table_w3n_2ph_rt}

## CIRelatedList - checkSysCollection() {#ariaid-title6}

Checks to see if this is a SysCollection table. If it is, sets the target table name
and reference field name.
{#r_CIRL-checkSysCollection__table_dn2_hnh_rt__entry__3}

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

{#r_CIRL-checkSysCollection__table_dn2_hnh_rt} {#r_CIRL-checkSysCollection__table_en2_hnh_rt__entry__2}

| Type | Description |
|-|-|
| CIRelatedList | An instance of CIRelatedList for the specified list. |
[Table 10. Returns]

{#r_CIRL-checkSysCollection__table_en2_hnh_rt}

## CIRelatedList - checkSysM2M() {#ariaid-title7}

Checks to see if this is a Sys many-to-many table. If it is, sets the target table name
and reference field name.
{#r_CIRL-checkSysM2M__table_knj_gmh_rt__entry__3}

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

{#r_CIRL-checkSysM2M__table_knj_gmh_rt} {#r_CIRL-checkSysM2M__table_lnj_gmh_rt__entry__2}

| Type | Description |
|-|-|
| Boolean | True if it is a sys many-to-many table; otherwise, false. |
[Table 12. Returns]

{#r_CIRL-checkSysM2M__table_lnj_gmh_rt}

## CIRelatedList - CIRelatedList(String table, String refField, String cmdb_ci, String
debugFlag) {#ariaid-title8}

Creates an instance of the CIRelatedList class. With no arguments, simply constructs an
empty instance.
{#r_CIRL-CIRelatedList_S_S_S_S__table_mxj_zjh_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| table | String | The table containing the related list. If many-to-many, the many-to-many table. |
| refField | String | The reference field in the table for this related list. |
| cmdb_ci | String | The sys_id of the CI this list is related to. |
| debugFlag | String | If true, debug logging is enabled. |
[Table 13. Parameters]

{#r_CIRL-CIRelatedList_S_S_S_S__table_mxj_zjh_rt}

## CIRelatedList - fromXML(String element) {#ariaid-title9}

Initializes this instance from the specified XML element.
{#r_CIRL-fromXML_S__table_jzb_tnh_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| element | String | An XML element |
[Table 14. Parameters]

{#r_CIRL-fromXML_S__table_jzb_tnh_rt} {#r_CIRL-fromXML_S__table_kzb_tnh_rt__entry__2}

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

{#r_CIRL-fromXML_S__table_kzb_tnh_rt}

## CIRelatedList - populate() {#ariaid-title10}

Populates the `this.records` field of this instance.
{#r_CIRL-populate__table_vfs_tkh_rt__entry__3}

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

{#r_CIRL-populate__table_vfs_tkh_rt} {#r_CIRL-populate__table_wfs_tkh_rt__entry__2}

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

{#r_CIRL-populate__table_wfs_tkh_rt}

## CIRelatedList - toString(Array result) {#ariaid-title11}

Makes a string representation of this instance, pushing each line onto the end of the
given result array.
This method is called from CIData.toString(), and assumes related list
lines are to be indented two spaces.
{#r_CIRL-toString_A__table_ss1_bqh_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| result | Array | The result to convert |
[Table 18. Parameters]

{#r_CIRL-toString_A__table_ss1_bqh_rt} {#r_CIRL-toString_A__table_ts1_bqh_rt__entry__2}

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

{#r_CIRL-toString_A__table_ts1_bqh_rt}

## CIRelatedList - toXML(String document, String element) {#ariaid-title12}

Serializes this instance to XML in the given document and \<rl\> element.
{#r_CIRL-toXML_S_S__table_edx_s4h_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| document | String | The document |
| element | String | The rl element |
[Table 20. Parameters]

{#r_CIRL-toXML_S_S__table_edx_s4h_rt} {#r_CIRL-toXML_S_S__table_fdx_s4h_rt__entry__2}

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

{#r_CIRL-toXML_S_S__table_fdx_s4h_rt}

## CIRelatedList - remove() {#ariaid-title13}

Removes all the related list items.
{#r_CIRL-remove__table_wzm_1lh_rt__entry__3}

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

{#r_CIRL-remove__table_wzm_1lh_rt} {#r_CIRL-remove__table_xzm_1lh_rt__entry__2}

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

{#r_CIRL-remove__table_xzm_1lh_rt}  
This code example deletes the related records mapped with the CI items with the name =
\*JEMPLOYEE-IBM. This example is for a non-M2M table.

    //Get a configuration item record which has a related list. Example:  CI items with the name = *JEMPLOYEE-IBM.
    var ciRecord = new GlideRecord("cmdb_ci_computer");
    ciRecord.addQuery("name", "*JEMPLOYEE-IBM");
    ciRecord.query();
    if (ciRecord.next()) {

        var relRecordTable = 'cmdb_ci_network_adapter'; // The table containing the related list (if many-to-many, the many-to-many table)
        var relRecordField = 'cmdb_ci'; // The reference field in the table for this related list
        var cmdb_ciHasRelRecord = ciRecord.sys_id; // The sys_id of the CI this list is related to.
        var debugFlag = 'true'; // True if debug logging is enabled.

        // Get the related record List
        var CIRelatedList = new CIRelatedList(relRecordTable, relRecordField, cmdb_ciHasRelRecord, debugFlag);
        CIRelatedList.remove(); // Delete all related records
    }

## CIRelatedList - xmlToRecord(String records, String element) {#ariaid-title14}

Converts a related list from XML to record format.
{#r_CIRL-xmlToRecord_S_S__table_k55_c4h_rt__entry__3}

| Name | Type | Description |
|-|-|-|
| records | String | The record to create |
| element | String | The XML element |
[Table 24. Parameters]

{#r_CIRL-xmlToRecord_S_S__table_k55_c4h_rt} {#r_CIRL-xmlToRecord_S_S__table_l55_c4h_rt__entry__2}

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

{#r_CIRL-xmlToRecord_S_S__table_l55_c4h_rt}

