|
| 1 | +(function executeRule(current, previous /*null when async*/ ) { |
| 2 | + |
| 3 | + // Copies the values from a multi-row variable set into a variable so we can view the values on a catalog task. |
| 4 | + var variables = []; |
| 5 | + var catItem = current.request_item.cat_item.toString(); |
| 6 | + var variableSets = []; |
| 7 | + var getVariableSets = new GlideRecord('io_set_item'); |
| 8 | + getVariableSets.addQuery('sc_cat_item', catItem); |
| 9 | + getVariableSets.query(); |
| 10 | + while (getVariableSets.next()) { |
| 11 | + variableSets.push(getVariableSets.getValue('variable_set')); |
| 12 | + } |
| 13 | + var getCatalogVariables = new GlideRecord('item_option_new'); |
| 14 | + var qry = 'cat_item=' + catItem + |
| 15 | + '^active=true' + |
| 16 | + '^NQvariable_set.sys_idIN' + variableSets.toString() + |
| 17 | + '^active=true'; |
| 18 | + getCatalogVariables.addQuery(qry); |
| 19 | + getCatalogVariables.query(); |
| 20 | + while (getCatalogVariables.next()) { |
| 21 | + variables.push(getCatalogVariables.getValue('sys_id')); |
| 22 | + } |
| 23 | + var variablesCount = variables.length; |
| 24 | + var currentTaskID = current.sys_id.toString(); |
| 25 | + for (var i = 0; i < variablesCount; i++) { |
| 26 | + var getTaskVars = new GlideRecord('sc_item_variables_task'); |
| 27 | + getTaskVars.addQuery('task', currentTaskID); |
| 28 | + getTaskVars.addQuery('variable', variables[i]); |
| 29 | + getTaskVars.setLimit(1); |
| 30 | + getTaskVars.query(); |
| 31 | + if (!getTaskVars.hasNext()) { |
| 32 | + getTaskVars.initialize(); |
| 33 | + getTaskVars.setValue('task', currentTaskID); |
| 34 | + getTaskVars.setValue('variable', variables[i]); |
| 35 | + getTaskVars.insert(); |
| 36 | + } |
| 37 | + } |
| 38 | +})(current, previous); |
0 commit comments