diff --git a/Server-Side Components/Business Rules/Copy MRVS to SC Task/readme.md b/Server-Side Components/Business Rules/Copy MRVS to SC Task/readme.md new file mode 100644 index 0000000000..306ea4260f --- /dev/null +++ b/Server-Side Components/Business Rules/Copy MRVS to SC Task/readme.md @@ -0,0 +1 @@ +Use the script as Business Rule script on Catalog Task table which runs After Insert and will copy all MRVS values from RITM to Catalog Task for quick actions at the Catalog Task itself for reviewing and getting the work completed. diff --git a/Server-Side Components/Business Rules/Copy MRVS to SC Task/script.js b/Server-Side Components/Business Rules/Copy MRVS to SC Task/script.js new file mode 100644 index 0000000000..4fed9b5029 --- /dev/null +++ b/Server-Side Components/Business Rules/Copy MRVS to SC Task/script.js @@ -0,0 +1,38 @@ +(function executeRule(current, previous /*null when async*/ ) { + + // Copies the values from a multi-row variable set into a variable so we can view the values on a catalog task. + var variables = []; + var catItem = current.request_item.cat_item.toString(); + var variableSets = []; + var getVariableSets = new GlideRecord('io_set_item'); + getVariableSets.addQuery('sc_cat_item', catItem); + getVariableSets.query(); + while (getVariableSets.next()) { + variableSets.push(getVariableSets.getValue('variable_set')); + } + var getCatalogVariables = new GlideRecord('item_option_new'); + var qry = 'cat_item=' + catItem + + '^active=true' + + '^NQvariable_set.sys_idIN' + variableSets.toString() + + '^active=true'; + getCatalogVariables.addQuery(qry); + getCatalogVariables.query(); + while (getCatalogVariables.next()) { + variables.push(getCatalogVariables.getValue('sys_id')); + } + var variablesCount = variables.length; + var currentTaskID = current.sys_id.toString(); + for (var i = 0; i < variablesCount; i++) { + var getTaskVars = new GlideRecord('sc_item_variables_task'); + getTaskVars.addQuery('task', currentTaskID); + getTaskVars.addQuery('variable', variables[i]); + getTaskVars.setLimit(1); + getTaskVars.query(); + if (!getTaskVars.hasNext()) { + getTaskVars.initialize(); + getTaskVars.setValue('task', currentTaskID); + getTaskVars.setValue('variable', variables[i]); + getTaskVars.insert(); + } + } +})(current, previous);