{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":974,"path":"api-reference/server-api-reference/c_CatalogItemVariableSet.md","title":"CatalogItemVariableSet - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# CatalogItemVariableSet- Scoped\n\nThe CatalogItemVariableSet API provides methods that enable you to create and modify service catalog item variable sets 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## CatalogItemVariableSet - create\\(Boolean standardUpdate\\)\n\nInserts the defined catalog item variable set.\n\n<table id=\"table_dk2_55d_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 indicating whether to enable the running of engines and workflow.Valid values:\n\n-   true: Enable the running of engines and workflow.\n-   false: Do not enable the running of engines and workflow.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the inserted variable record.|\n\n```\n// Given an existing catalog item\nvar catItemSysId = \"e0d08b13c3330100c8b837659bba8fb4\";\naddVariableSets(catItemSysId);\n\nfunction addVariableSets(catItemSysId) {\n  // List of all variable sets to attach\n  var myVarSets = [];\n\n  // Create variable set\n  var myVarSetAttrs = {\"name\": \"Requester details\", \"order\": \"100\"};\n  var myVarSet = new sn_sc.CatalogItemVariableSet();\n  myVarSet.setAttributes(myVarSetAttrs);\n  var myVarSetId = myVarSet.create(true);\n  myVarSets.push(myVarSetId);\n}\n```\n\n## CatalogItemVariableSet - deleteRecord\\(Boolean standardUpdate\\)\n\nDeletes a variable set.\n\n<table id=\"table_rzk_z5d_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 My Variable Set from all catalog items that use it, and then deletes My Variable Set.\n\n```\n// Get the sys_id of the variable set you want to delete\nvar vSet = new GlideRecord('item_option_new_set');\nvSet.addEncodedQuery('title=My Variable Set'); // find My Variable Set\nvSet.query();\nif (vSet.next()) {\n\n    // first remove the variable set from all catalog items\n    var catItemVset = new GlideRecord('io_set_item'); // M2M table linking variable set and catalog item\n    catItemVset.addQuery('variable_set', vSet.getUniqueValue); // find all catalog items using My Variable Set\n    catItemVset.query();\n    while (catItemVset.next()) {\n        var vsetM2M = new sn_sc.CatalogItemVariableSetM2M(catItemVset.getUniqueValue()); // io_set_item M2M record sys_id\n        vsetM2M.deleteRecord(true); // delete M2M record\n    }\n\n    // then delete the variable set record\n    var varset = new sn_sc.CatalogItemVariableSet(vSet.getUniqueValue()); \n    varset.deleteRecord(true);\n}\n\n```\n\n## CatalogItemVariableSet - read\\(Object columns, Boolean standardUpdate\\)\n\nReturns a mapping of catalog item variable set attribute values.\n\n<table id=\"table_k4p_dvd_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\nSpecify the set 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\n## CatalogItemVariableSet - setAttributes\\(Object attributes\\)\n\nSets attributes for a variable set.\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 creates a variable set and then adds a variable to the new set.\n\n```\ncreateVariableSet('My Variable Set', 'This is my test variable set', '100', 'one_to_one');\n\nfunction createVariableSet(name, description, order, type) {\n    var myVarSet = new sn_sc.CatalogItemVariableSet();\n    // fields used in object are from table item_option_new_set\n    var myVarSetAttrs = {\n        \"name\": name,\n        \"description\": description,\n        \"order\": order,\n        \"type\": type\n    }; \n    myVarSet.setAttributes(myVarSetAttrs);\n    var myVarSetId = myVarSet.create(true); // returns the sys_id of the created variable set\n    gs.info('Variable set created in table item_option_new_set with sys_id ' + myVarSetId);\n\n    // add a variable to the newly created variable set\n    var myVar = new sn_sc.CatalogItemVariable();\n    var myVarAttrs = {\n        \"type\": \"6\", // type 6 is single line text\n        \"variable_set\": myVarSetId.toString(), \n        \"question_text\": \"Example question\",\n        \"name\": \"example_question\",\n        \"order\": 200\n    };\n    myVar.setAttributes(myVarAttrs);\n    myVar.create(true);\n}\n```\n\nOutput:\n\n```\nVariable set created in table item_option_new_set with sys_id e21df65a1bff7c10593876a61a4bcbc4\n\n```\n\n## CatalogItemVariableSet - update\\(Object columnValues, Boolean standardUpdate\\)\n\nUpdates a variable set.\n\n<table id=\"table_z35_5vd_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 description and order for the Standard Employee Questions variable set.\n\n```\n// Get the sys_id of the variable set you want to update\nvar vSet = new GlideRecord('item_option_new_set');\nvSet.addEncodedQuery('title=Standard Employee Questions'); // find the Standard Employee Questions variable set\nvSet.query();\nif (vSet.next()) {\n    var varset = new sn_sc.CatalogItemVariableSet(vSet.getUniqueValue()); \n    var attr = {\n        'description': 'This should be used for all end user requests such as phones, tablets, etc. \\n My description line',\n        'order': '500' \n    };\n    varset.update(attr, true);\n}\n```\n\n"}}