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


---

# CatalogItemVariableSetM2M - Scoped

# CatalogItemVariableSetM2M - Scoped {#ariaid-title1}

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

The CatalogItemVariableSetM2M API provides methods that enable you to create and modify service catalog item variable set many-to-many (M2Ms) using scripts.

This API runs in the `sn_sc` namespace.

## CatalogItemVariableSetM2M - create(Boolean standardUpdate) {#ariaid-title2}

Inserts the defined catalog item variable set M2M.
{#r_CatalogItemVariableSetM2M-create_Boolean__table_rrn_wwd_ns__entry__3}

| Name | Type | Description |
|-|-|-|
| standardUpdate | Boolean | Flag that indicates whether to enable the running of engines and workflow. Valid values: * true: Enable engines and workflow. * false: Do not enable engines and workflow. {#r_CatalogItemVariableSetM2M-create_Boolean__ul_nnx_xwn_kpb} |
[Table 1. Parameters]

{#r_CatalogItemVariableSetM2M-create_Boolean__table_rrn_wwd_ns} {#r_CatalogItemVariableSetM2M-create_Boolean__table_srn_wwd_ns__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the inserted variable record. |
[Table 2. Returns]

{#r_CatalogItemVariableSetM2M-create_Boolean__table_srn_wwd_ns}  
This example adds the Standard Employee Questions variable set to the iPhone 6s catalog
item and creates a record linking them in the Catalog Variable Sets table \[io_set_item\].

    var cat_item_sys_id = 'bd6fa75a4f334200086eeed18110c79e'; // catalog item - iPhone 6s
    var variable_set_sys_id = 'e01cab1a4f334200086eeed18110c71f'; // variable set - Standard Employee Questions
    var app_scope = 'global'; // sys_id id in case of scoped app
    var varset = new sn_sc.CatalogItemVariableSetM2M();
    var attr = {
        'variable_set': variable_set_sys_id, // required
        'sc_cat_item': cat_item_sys_id, // required
        'sys_scope': app_scope, // optional
        'order': 10 // optional
    };
    varset.setAttributes(attr);
    var m2mRec = varset.create(true);
    gs.info('Variable set added to catalog item and M2M record created in table io_set_item with sys_id ' + m2mRec);

Output:

    Variable set added to catalog item and M2M record created in table io_set_item with sys_id c5c87af187eb30103a730f2d0ebb3578

## CatalogItemVariableSetM2M - deleteRecord(Boolean standardUpdate) {#ariaid-title3}

Deletes the defined catalog item variable set M2M.
{#r_CatalogItemVariableSetM2M-deleteRecord_Boolean__table_v2c_1xd_ns__entry__3}

| Name | Type | Description |
|-|-|-|
| standardUpdate | Boolean | Flag that indicates whether to enable the running of engines and workflow. Valid values: * true: Enable engines and workflow. * false: Do not enable engines and workflow. {#r_CatalogItemVariableSetM2M-deleteRecord_Boolean__ul_nnx_xwn_kpb} |
[Table 3. Parameters]

{#r_CatalogItemVariableSetM2M-deleteRecord_Boolean__table_v2c_1xd_ns} {#r_CatalogItemVariableSetM2M-deleteRecord_Boolean__table_w2c_1xd_ns__entry__2}

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

{#r_CatalogItemVariableSetM2M-deleteRecord_Boolean__table_w2c_1xd_ns}  
This example removes the Standard Employee Questions variable set from the iPhone 6s
catalog item and deletes the record linking them in the Catalog Variable Sets table
\[io_set_item\].

    var vset = new GlideRecord('io_set_item');
    vset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s
    vset.addQuery('variable_set', 'e01cab1a4f334200086eeed18110c71f'); // variable set - Standard Employee Questions
    vset.query();
    if (vset.next()) {
        var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record
        varset.deleteRecord(true);  
    }

## CatalogItemVariableSetM2M - read(Object columns, Boolean standardUpdate) {#ariaid-title4}

Returns a mapping of catalog item variable set M2M attribute values.
{#r_CatalogItemVariableSetM2M-read_Object_Boolean__table_uxc_fxd_ns__entry__3}

| Name | Type | Description |
|-|-|-|
| columns | Object | Set of columns that you would like the values for. |
| standardUpdate | Boolean | Flag that indicates whether to enable the running of engines and workflow. Valid values: * true: Enable engines and workflow. * false: Do not enable engines and workflow. {#r_CatalogItemVariableSetM2M-read_Object_Boolean__ul_nnx_xwn_kpb} |
[Table 5. Parameters]

{#r_CatalogItemVariableSetM2M-read_Object_Boolean__table_uxc_fxd_ns} {#r_CatalogItemVariableSetM2M-read_Object_Boolean__table_vxc_fxd_ns__entry__2}

| Type | Description |
|-|-|
| Object | An object mapping column names to values. |
[Table 6. Returns]

{#r_CatalogItemVariableSetM2M-read_Object_Boolean__table_vxc_fxd_ns}  
This example reads all variable sets that are used by the iPhone 6s catalog item.

    var vset = new GlideRecord('io_set_item');
    vset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s
    vset.query();
    while (vset.next()) {
        var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record
        //add the fields you want to read from the record
        var attr = {
            'sys_name': '', // optional
            'sys_scope': '', // optional
            'order': '' // optional
        };
        var m2mRec = varset.read(attr, true);
        gs.info(JSON.stringify(m2mRec));
    }

Output:

    {"sys_name":"HTML Description.iPhone 6s","sys_scope":"global","order":"10"}
    {"sys_name":"Standard Employee Questions.iPhone 6s","sys_scope":"global","order":"20"}

## CatalogItemVariableSetM2M - setAttributes(Object attributes) {#ariaid-title5}

Defines attribute values for this catalog item variable set M2M.
{#r_CatalogItemVariableSetM2M-setAttributes_Map__table_tyz_qxd_ns__entry__3}

| Name | Type | Description |
|-|-|-|
| attributes | Object | An object mapping column names to values. |
[Table 7. Parameters]

{#r_CatalogItemVariableSetM2M-setAttributes_Map__table_tyz_qxd_ns} {#r_CatalogItemVariableSetM2M-setAttributes_Map__table_uyz_qxd_ns__entry__2}

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

{#r_CatalogItemVariableSetM2M-setAttributes_Map__table_uyz_qxd_ns}  
This example adds the Standard Employee Questions variable set to the iPhone 6s catalog
item and creates a record in the Catalog Variable Sets table \[io_set_item\].

    var cat_item_sys_id = 'bd6fa75a4f334200086eeed18110c79e'; // catalog item - iPhone 6s
    var variable_set_sys_id = 'e01cab1a4f334200086eeed18110c71f'; // variable set - Standard Employee Questions
    var app_scope = 'global'; // sys_id id in case of scoped app
    var varset = new sn_sc.CatalogItemVariableSetM2M();
    var attr = {
        'variable_set': variable_set_sys_id,
        'sc_cat_item': cat_item_sys_id,
        'sys_scope': app_scope,
        'order': 10
    };
    varset.setAttributes(attr);
    var m2mRec = varset.create(true);
    gs.info('Variable set added to catalog item and M2M record created in table io_set_item with sys_id ' + m2mRec);

Output:

    Variable set added to catalog item and M2M record created in table io_set_item with sys_id c5c87af187eb30103a730f2d0ebb3578

## CatalogItemVariableSetM2M - update(Object columnValues, Boolean standardUpdate) {#ariaid-title6}

Updates current catalog item variable set M2M with set values.
{#r_CatalogItemVariableSetM2M-update_Object_Boolean__table_dj1_cyd_ns__entry__3}

| Name | Type | Description |
|-|-|-|
| columnValues | Object | An object mapping column names to values. |
| standardUpdate | Boolean | Flag that indicates whether to enable the running of engines and workflow. Valid values: * true: Enable engines and workflow. * false: Do not enable engines and workflow. {#r_CatalogItemVariableSetM2M-update_Object_Boolean__ul_nnx_xwn_kpb} |
[Table 9. Parameters]

{#r_CatalogItemVariableSetM2M-update_Object_Boolean__table_dj1_cyd_ns} {#r_CatalogItemVariableSetM2M-update_Object_Boolean__table_ej1_cyd_ns__entry__2}

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

{#r_CatalogItemVariableSetM2M-update_Object_Boolean__table_ej1_cyd_ns}  
This example updates the order of the Standard Employee Questions variable set for the
iPhone 6s catalog item.

    var vset = new GlideRecord('io_set_item');
    vset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s
    vset.addQuery('variable_set', 'e01cab1a4f334200086eeed18110c71f'); // variable set - Standard Employee Questions
    vset.query();
    if (vset.next()) {
        var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record
        var attr = {
            'order': '30' // update order to 30
        };
        varset.update(attr, true);
        var readAttr = {
            'sys_name': '',
            'order': '' 
        };
        var m2mRec = varset.read(readAttr, true); // read the record to confirm the update 
        gs.info(JSON.stringify(m2mRec));
    }

Output:

    {"sys_name":"Standard Employee Questions.iPhone 6s","order":"30"}


