MRV to Create a new Catalog task for each row

Sam Ogden
Tera Guru

Hi All,

We have a catalog item which contains a tasks of 'triage'.  The user then needs to identify all areas of the business that need to do an impact assessment for the item.  I was thinking of using a Multi Row Variable set which would contain 2 columns (assignment group & details) on the catalog task so the user doing the triage can add in each area that needs to do an impact assessment.
When the user closes the triage task I would want a catalog task to be created for each row in the MRV with the assignment group variable setting the assignment group and the details variable being the description field?

Any help on this would be greatly appreciated.

Thanks

Sam

6 REPLIES 6

Hi James,

Thanks for the above detail.  I had written a script which is a lot shorter than the one you have proposed.  I'm still getting to grips with javascript so would appreciate the advice on where my script needs improvement:

var mrvs = current.variables.cim_triage;
var rowCount = mrvs.getRowCount();
var catTask = new GlideRecord('sc_task');
for (var i=0; i < rowCount; i++) {
	var row = mrvs.getRow(i);
	var group = row.assignment_group;
	var details = row.details;
	
	catTask.initialize();
	catTask.short_description = 'IA Task';
	catTask.description = details;
	catTask.assignment_group = group;
	catTask.request_item = current.getUniqueValue();
	catTask.insert();
}

Hi James, 

I have a requirements with exactly what you discussed above. However, the script include you provided did not work for me. It is not creating any catalog task .Would you mind to assist where I am missing here?

Script include:

var TaskGenerator = Class.create();
TaskGenerator.prototype = {
initialize: function() {},
generateTask: function (current) { //current object in the RITM
var mrvArrVals = this._getValues(current); //returns 2d array of MRVS values!

for (var i = 0; i < mrvArrVals.length; i++) {
var name = mrvArrVals[i][0];
var email = mrvArrVals[i][1];
var tasks = new GlideRecord('sc_task');
tasks.initialize();
tasks.short_description = name;
tasks.description = email;
tasks.request_item = current.sys_id;
tasks.insert();
}

},
_getValues: function (ritm) {

var mrvs;
var valueArr = [];
var valueArrays = [];
var sets = new GlideRecord('item_option_new_set');
sets.addQuery('title', 'Users Who Need Access');
sets.setLimit(1);
sets.query();

if (sets.next()) {
mrvs = sets.internal_name;
}

if (ritm) {
var m = ritm.variables[mrvs];
var mrvParsed = JSON.parse(ritm.variables[mrvs]);
var setCount = mrvParsed.length;
var keys = Object.keys(mrvParsed[0]) + '';
var keysArr = keys.split(',');

//iterate through obj
for (var i = 0; i < setCount; i++) {
//iterate through keys
for (var j = 0; j < keysArr.length; j++) {
//check if user entered value
if (keysArr[j]) {
valueArr.push(mrvParsed[i][keysArr[j]]);

} else {
valueArr.push("no data entered");
}
}
valueArrays.push(valueArr);
valueArr = []; //clear the array to repopulate it with next object values
}
}
return valueArrays;
},

type: 'TaskGenerator'
};

 

Then I called this in my workflow, but it is not generating any sctask. 

 

var generator = new TaskGenerator();
generator.generateTask(); //called from workflow

 

Appreciate your assistance on this.

 

thanks,

Sarah