{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":975,"path":"api-reference/server-api-reference/c_CatalogItemVariableSetM2M.md","title":"CatalogItemVariableSetM2M - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# CatalogItemVariableSetM2M- Scoped\n\nThe CatalogItemVariableSetM2M API provides methods that enable you to create and modify service catalog item variable set many-to-many \\(M2Ms\\) using scripts.\n\nThis API runs in the `sn_sc` namespace.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## CatalogItemVariableSetM2M - create\\(Boolean standardUpdate\\)\n\nInserts the defined catalog item variable set M2M.\n\n<table id=\"table_rrn_wwd_ns\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstandardUpdate\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to enable the running of engines and workflow.Valid values:\n\n-   true: Enable engines and workflow.\n-   false: Do not enable engines and workflow.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the inserted variable record.|\n\nThis 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\\].\n\n```\nvar cat_item_sys_id = 'bd6fa75a4f334200086eeed18110c79e'; // catalog item - iPhone 6s\nvar variable_set_sys_id = 'e01cab1a4f334200086eeed18110c71f'; // variable set - Standard Employee Questions\nvar app_scope = 'global'; // sys_id id in case of scoped app\nvar varset = new sn_sc.CatalogItemVariableSetM2M();\nvar attr = {\n    'variable_set': variable_set_sys_id, // required\n    'sc_cat_item': cat_item_sys_id, // required\n    'sys_scope': app_scope, // optional\n    'order': 10 // optional\n};\nvarset.setAttributes(attr);\nvar m2mRec = varset.create(true);\ngs.info('Variable set added to catalog item and M2M record created in table io_set_item with sys_id ' + m2mRec);\n```\n\nOutput:\n\n```\nVariable set added to catalog item and M2M record created in table io_set_item with sys_id c5c87af187eb30103a730f2d0ebb3578\n```\n\n## CatalogItemVariableSetM2M - deleteRecord\\(Boolean standardUpdate\\)\n\nDeletes the defined catalog item variable set M2M.\n\n<table id=\"table_v2c_1xd_ns\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstandardUpdate\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to enable the running of engines and workflow.Valid values:\n\n-   true: Enable engines and workflow.\n-   false: Do not enable engines and workflow.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis 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\\].\n\n```\nvar vset = new GlideRecord('io_set_item');\nvset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s\nvset.addQuery('variable_set', 'e01cab1a4f334200086eeed18110c71f'); // variable set - Standard Employee Questions\nvset.query();\nif (vset.next()) {\n    var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record\n    varset.deleteRecord(true);  \n}\n```\n\n## CatalogItemVariableSetM2M - read\\(Object columns, Boolean standardUpdate\\)\n\nReturns a mapping of catalog item variable set M2M attribute values.\n\n<table id=\"table_uxc_fxd_ns\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ncolumns\n\n</td><td>\n\nObject\n\n</td><td>\n\nSet of columns that you would like the values for.\n\n</td></tr><tr><td>\n\nstandardUpdate\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to enable the running of engines and workflow.Valid values:\n\n-   true: Enable engines and workflow.\n-   false: Do not enable engines and workflow.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|Object|An object mapping column names to values.|\n\nThis example reads all variable sets that are used by the iPhone 6s catalog item.\n\n```\nvar vset = new GlideRecord('io_set_item');\nvset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s\nvset.query();\nwhile (vset.next()) {\n    var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record\n    //add the fields you want to read from the record\n    var attr = {\n        'sys_name': '', // optional\n        'sys_scope': '', // optional\n        'order': '' // optional\n    };\n    var m2mRec = varset.read(attr, true);\n    gs.info(JSON.stringify(m2mRec));\n}\n```\n\nOutput:\n\n```\n{\"sys_name\":\"HTML Description.iPhone 6s\",\"sys_scope\":\"global\",\"order\":\"10\"}\n{\"sys_name\":\"Standard Employee Questions.iPhone 6s\",\"sys_scope\":\"global\",\"order\":\"20\"}\n\n```\n\n## CatalogItemVariableSetM2M - setAttributes\\(Object attributes\\)\n\nDefines attribute values for this catalog item variable set M2M.\n\n|Name|Type|Description|\n|----|----|-----------|\n|attributes|Object|An object mapping column names to values.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis 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\\].\n\n```\nvar cat_item_sys_id = 'bd6fa75a4f334200086eeed18110c79e'; // catalog item - iPhone 6s\nvar variable_set_sys_id = 'e01cab1a4f334200086eeed18110c71f'; // variable set - Standard Employee Questions\nvar app_scope = 'global'; // sys_id id in case of scoped app\nvar varset = new sn_sc.CatalogItemVariableSetM2M();\nvar attr = {\n    'variable_set': variable_set_sys_id,\n    'sc_cat_item': cat_item_sys_id,\n    'sys_scope': app_scope,\n    'order': 10\n};\nvarset.setAttributes(attr);\nvar m2mRec = varset.create(true);\ngs.info('Variable set added to catalog item and M2M record created in table io_set_item with sys_id ' + m2mRec);\n```\n\nOutput:\n\n```\nVariable set added to catalog item and M2M record created in table io_set_item with sys_id c5c87af187eb30103a730f2d0ebb3578\n```\n\n## CatalogItemVariableSetM2M - update\\(Object columnValues, Boolean standardUpdate\\)\n\nUpdates current catalog item variable set M2M with set values.\n\n<table id=\"table_dj1_cyd_ns\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ncolumnValues\n\n</td><td>\n\nObject\n\n</td><td>\n\nAn object mapping column names to values.\n\n</td></tr><tr><td>\n\nstandardUpdate\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to enable the running of engines and workflow.Valid values:\n\n-   true: Enable engines and workflow.\n-   false: Do not enable engines and workflow.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis example updates the order of the Standard Employee Questions variable set for the iPhone 6s catalog item.\n\n```\nvar vset = new GlideRecord('io_set_item');\nvset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s\nvset.addQuery('variable_set', 'e01cab1a4f334200086eeed18110c71f'); // variable set - Standard Employee Questions\nvset.query();\nif (vset.next()) {\n    var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record\n    var attr = {\n        'order': '30' // update order to 30\n    };\n    varset.update(attr, true);\n    var readAttr = {\n        'sys_name': '',\n        'order': '' \n    };\n    var m2mRec = varset.read(readAttr, true); // read the record to confirm the update \n    gs.info(JSON.stringify(m2mRec));\n}\n```\n\nOutput:\n\n```\n{\"sys_name\":\"Standard Employee Questions.iPhone 6s\",\"order\":\"30\"}\n```\n\n"}}