I have to create unique catalog task based on location selected in MRVS.

Mishu
Tera Expert

Have to create catalog tasks based on the different locations selected in MRVS. Say if the requester submits the details below, then depending on the number of different locations selected in the multirow variable set in each row, the number of catalog tasks should be created.  

 

For instance : 1 single task for Abel and David for the Delhi location , another task for Willa for Mumbai location

 

Mishu_0-1727339196590.png

 

What changes should I make in below script to make it work for my requirement, currently it is creating task for each row:

var mrvs = current.variables.customer_regist;
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.dc_location;
var details = row.details;

catTask.initialize();
catTask.short_description = "Task for DC Location" + row.dc_location;
catTask.description = details;
catTask.assignment_group = group;
catTask.request_item = current.getUniqueValue();
catTask.insert();
}

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You could try to sort the MRVS data by the DC Location variable, then when going through the loop check if the row group matches the previous row group before adding the record, but this approach might be easier:

var locArr = [];
var mrvs = current.variables.customer_regist;
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.dc_location;
    var details = row.details;
	if (locArr.indexOf(group) == -1) { //row DC Location not found in array of locations already created
		locArr.push(group.toString());
 	   catTask.initialize();
    	catTask.short_description = "Task for DC Location" + group;
    	catTask.description = details;
    	catTask.assignment_group = group;
    	catTask.request_item = current.getUniqueValue();
    	catTask.insert();
	}
}

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

You could try to sort the MRVS data by the DC Location variable, then when going through the loop check if the row group matches the previous row group before adding the record, but this approach might be easier:

var locArr = [];
var mrvs = current.variables.customer_regist;
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.dc_location;
    var details = row.details;
	if (locArr.indexOf(group) == -1) { //row DC Location not found in array of locations already created
		locArr.push(group.toString());
 	   catTask.initialize();
    	catTask.short_description = "Task for DC Location" + group;
    	catTask.description = details;
    	catTask.assignment_group = group;
    	catTask.request_item = current.getUniqueValue();
    	catTask.insert();
	}
}

Thanks Brad, it worked for me 🙂

Great to hear - happy to help!