Create each task for every entry on Multi Row Variable Set (MRVS)

Shruti Navalgu1
Kilo Contributor

I am trying to create each task for every entry on the multi-row variable set. I am using flow designer to achieve but it doesn't work, please let me know if there is any other way to get through this

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hello Shruti,

You can write after Br on sc_req_item and can create catalog tasks. you can try like this

After insert on sc_req_item

condition: item is <your_cat_item>

Script

var mrvs = current.variables.your_mrvs_name;
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
  //if you wnat to read data from mrvs and assign to task then
  var row = mrvs.getRow(i);
  var sc_task = new GlideRecord("sc_task");
  sc_task.initialize();
  sc_task.short_description = row.your_variable;
  sc_task.insert();
}

Mark the comment as a correct answer and also helpful if it helps to solve the problem.

 

View solution in original post

18 REPLIES 18

asifnoor
Kilo Patron

Hello Shruti,

You can write after Br on sc_req_item and can create catalog tasks. you can try like this

After insert on sc_req_item

condition: item is <your_cat_item>

Script

var mrvs = current.variables.your_mrvs_name;
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
  //if you wnat to read data from mrvs and assign to task then
  var row = mrvs.getRow(i);
  var sc_task = new GlideRecord("sc_task");
  sc_task.initialize();
  sc_task.short_description = row.your_variable;
  sc_task.insert();
}

Mark the comment as a correct answer and also helpful if it helps to solve the problem.

 

Thanks a ton Asif 🙂

Have used the below script in the workflow to create multiple task 🙂 , Thanks again for making me think in another perspective of developing this- 

(function executeRule(current, previous /*null when async*/) {

gs.info('>>> DEBUG');
gs.log('>>> DEBUG');


var rowsInt = current.variables.for_bulk_request.getRowCount();

for(var i = 0; i < rowsInt; i++) {
var grtask = new GlideRecord('sc_task');
gs.log('>>> DEBUG1');

grtask.initialize();
grtask.setValue('request_item', current.getUniqueValue());
grtask.setValue('short_description', current.variables.for_bulk_request.getRow(i).short_description);
grtask.insert();
}

})(current, previous);

 

Regards,

Shruti

Hi Asif,

Indeed the answer is right, I realized after posting the reply :).

So far I was trying through a BR which didn't create task, I had to do it workflow 😞

Really thankful for guiding me through.

 

Thanks,

Shruti

Zo2
Tera Contributor

Hi, This worked great for me and i have used it to create child RITM's instead of tasks. the MRVS is working as expected but how do i add the parent ritm to the child ritms created? This is the final hurdle for this particular area. Your help is much appreciated.

I tried doing an update after the insert part of the script of the child ritms but doesnt seem to work.