CatalogItemVariableSet – Scoped
Mit der CatalogItemVariableSet- API können Sie Variablensätze für Servicekatalogelemente mithilfe von Skripts erstellen und ändern.
Diese API wird im Namespace sn_sc ausgeführt.
CatalogItemVariableSet – create(Boolean standardUpdate)
Fügt den definierten Katalogelement-Variablensatz ein.
| Name | Typ | Beschreibung |
|---|---|---|
| standardUpdate | Boolean | Kennzeichnung, die angibt, ob die Ausführung von Engines und Workflows aktiviert werden soll. Gültige Werte:
|
| Typ | Beschreibung |
|---|---|
| Zeichenfolge | Sys_id des eingefügten Variablendatensatzes. |
// Given an existing catalog item
var catItemSysId = "e0d08b13c3330100c8b837659bba8fb4";
addVariableSets(catItemSysId);
function addVariableSets(catItemSysId) {
// List of all variable sets to attach
var myVarSets = [];
// Create variable set
var myVarSetAttrs = {"name": "Requester details", "order": "100"};
var myVarSet = new sn_sc.CatalogItemVariableSet();
myVarSet.setAttributes(myVarSetAttrs);
var myVarSetId = myVarSet.create(true);
myVarSets.push(myVarSetId);
}
CatalogItemVariableSet – deleteRecord(Boolean standardUpdate)
Löscht einen Variablensatz.
| Name | Typ | Beschreibung |
|---|---|---|
| standardUpdate | Boolean | Kennzeichnung, die angibt, ob die Ausführung von Engines und Workflows aktiviert werden soll. Gültige Werte:
|
| Typ | Beschreibung |
|---|---|
| void |
In diesem Beispiel wird „Mein Variablensatz“ aus allen Katalogelementen entfernt, die ihn verwenden, und dann wird „Mein Variablensatz“ gelöscht.
// Get the sys_id of the variable set you want to delete
var vSet = new GlideRecord('item_option_new_set');
vSet.addEncodedQuery('title=My Variable Set'); // find My Variable Set
vSet.query();
if (vSet.next()) {
// first remove the variable set from all catalog items
var catItemVset = new GlideRecord('io_set_item'); // M2M table linking variable set and catalog item
catItemVset.addQuery('variable_set', vSet.getUniqueValue); // find all catalog items using My Variable Set
catItemVset.query();
while (catItemVset.next()) {
var vsetM2M = new sn_sc.CatalogItemVariableSetM2M(catItemVset.getUniqueValue()); // io_set_item M2M record sys_id
vsetM2M.deleteRecord(true); // delete M2M record
}
// then delete the variable set record
var varset = new sn_sc.CatalogItemVariableSet(vSet.getUniqueValue());
varset.deleteRecord(true);
}
CatalogItemVariableSet – read(Object columns, Boolean standardUpdate)
Gibt eine Zuordnung der Attributwerte des Katalogelement-Variablensatzes zurück.
| Name | Typ | Beschreibung |
|---|---|---|
| columns | Objekt | Geben Sie die Spaltengruppe an, für die Sie die Werte wünschen. |
| standardUpdate | Boolean | Kennzeichnung, die angibt, ob die Ausführung von Engines und Workflows aktiviert werden soll. Gültige Werte:
|
| Typ | Beschreibung |
|---|---|
| Objekt | Ein Objekt, das Werten Spaltennamen zuordnet. |
CatalogItemVariableSet – setAttributes(Object attributes)
Legt Attribute für einen Variablensatz fest.
| Name | Typ | Beschreibung |
|---|---|---|
| attributes | Objekt | Ein Objekt, das Werten Spaltennamen zuordnet. |
| Typ | Beschreibung |
|---|---|
| void |
In diesem Beispiel wird ein Variablensatz erstellt und dem neuen Satz wird dann eine Variable hinzugefügt.
createVariableSet('My Variable Set', 'This is my test variable set', '100', 'one_to_one');
function createVariableSet(name, description, order, type) {
var myVarSet = new sn_sc.CatalogItemVariableSet();
// fields used in object are from table item_option_new_set
var myVarSetAttrs = {
"name": name,
"description": description,
"order": order,
"type": type
};
myVarSet.setAttributes(myVarSetAttrs);
var myVarSetId = myVarSet.create(true); // returns the sys_id of the created variable set
gs.info('Variable set created in table item_option_new_set with sys_id ' + myVarSetId);
// add a variable to the newly created variable set
var myVar = new sn_sc.CatalogItemVariable();
var myVarAttrs = {
"type": "6", // type 6 is single line text
"variable_set": myVarSetId.toString(),
"question_text": "Example question",
"name": "example_question",
"order": 200
};
myVar.setAttributes(myVarAttrs);
myVar.create(true);
}
Ausgabe:
Variable set created in table item_option_new_set with sys_id e21df65a1bff7c10593876a61a4bcbc4
CatalogItemVariableSet – update(Object columnValues, Boolean standardUpdate)
Aktualisiert einen Variablensatz.
| Name | Typ | Beschreibung |
|---|---|---|
| columnValues | Objekt | Ein Objekt, das Werten Spaltennamen zuordnet. |
| standardUpdate | Boolean | Kennzeichnung, die angibt, ob die Ausführung von Engines und Workflows aktiviert werden soll. Gültige Werte:
|
| Typ | Beschreibung |
|---|---|
| void |
In diesem Beispiel werden die Beschreibung und die Reihenfolge für den Variablensatz „Standard Employee Questions“ aktualisiert.
// Get the sys_id of the variable set you want to update
var vSet = new GlideRecord('item_option_new_set');
vSet.addEncodedQuery('title=Standard Employee Questions'); // find the Standard Employee Questions variable set
vSet.query();
if (vSet.next()) {
var varset = new sn_sc.CatalogItemVariableSet(vSet.getUniqueValue());
var attr = {
'description': 'This should be used for all end user requests such as phones, tablets, etc. \n My description line',
'order': '500'
};
varset.update(attr, true);
}