- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 02:18 AM - edited 09-26-2024 02:20 AM
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
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();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 02:56 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 02:56 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 04:01 AM
Thanks Brad, it worked for me 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 04:23 AM
Great to hear - happy to help!