How to copy/print MRVS (Multi row variable set) values to catalog task description?

Ronak3
Tera Contributor

Hi Community,

My catalog item contains MRVS which contains reference (application to select), select box & text variables. How do we copy these values selected onto the catalog task description? 

Tricky part is, Each row with different reference variable selected will create a catalog task per row . There can be multiple tasks generated. And that catalog task description should contain only that row variable values.

1 ACCEPTED SOLUTION

A script like this should get you close.

var mrvs = current.variables.mrvs_internal_name;//replace with the internal name of your MRVS
var rowCount = mrvs.getRowCount();
for(var i = 0; i < rowCount; i++){
  var row = mrvs.getRow(i);	
  var app = new GlideRecord('cmdb_ci_business_app');//replace with the reference table name of your MRVS application reference variable
  app.addQuery('sys_id', row.v_mrvs_application);//replace with the name of your MRVS aplication reference variable
  app.query();
  if(app.next()){
    if(app.assignment_group == task.assignment_group){
      task.description = 'some text ' + row.v_variable1_name + ' some more text ' + row.v_variable2_name;
    }
  }
}

View solution in original post

8 REPLIES 8

Brad Bowman
Kilo Patron
Kilo Patron

Hi Ronak,

Here is a script I am using on a Catalog Task activity in a workflow to do something similar.  If you are not using a workflow, or the workflow is not using the Catalog Task activity, you could probably add something similar to your script that is creating the tasks.  I just wanted to give you the context - so 'current' refers to the sc_req_item record since that's the table the workflow is running on. v_mrvs_model is a reference variable on the cmdb_model table, so you'll see a section near the beginning where I am retrieving the model display name to use in the task description, instead of the sys_id that the reference variable stores.  If your select box choice values are not the same as the label, I'm thinking there might be an easy way to get that, but I can't think of it right now, so we'll attack that later if needed.  Now, the tricky part about one task per row.  Are you currently doing this - are the tasks already being created, you just need to populate the right row in the description, or is this all high level what needs to be done?  Hopefully it's the former in which case I'd say whatever key variable in the MRVS you used to create the tasks, we'll use the same to locate the correct row in the MRVS to use.  In my example script I'm going through all of the rows in the MRVS to print the Model Display Name, and the Quantity requested (also a variable in the MRVS).  Here's how to get started.

var modelstring = '';
var mrvs1 = current.variables.network_gear_model_mrvs;//internal name of your MRVS
var rowCount = mrvs1.getRowCount();
for(var i = 0; i < rowCount; i++){//go through each row to lookup the Model Display Name of the reference variable in the MRVS
	var row = mrvs1.getRow(i);
	var mdl = new GlideRecord('cmdb_model');
	mdl.addQuery('sys_id', row.v_mrvs1_model);
	mdl.query();
	if(mdl.next()){
		if(modelstring == ''){
			modelstring = 'Which model of network gear do you need: ' + mdl.display_name + '\nQuantity to order: ' + row.v_mrvs1_quantity_to_order + '\n';
		}
		else{
			modelstring = modelstring + 'Which model of network gear do you need: ' + mdl.display_name + '\nQuantity to order: ' + row.v_mrvs1_quantity_to_order + '\n';
		}
	}
}

task.description = 'Request Opened by: ' + current.request.opened_by.getDisplayValue() + "\n" + 'Requested On behalf of: ' + current.request.requested_for.getDisplayValue() + "\n" + 'Vendor: ' + current.variables.v_vendor.name + "\n" + modelstring;

Hi Brad,

Sorry I was stuck with other work and couldn't check back on this even it has to be completed. See my reply in Blue to your question,

Are you currently doing this - are the tasks already being created, you just need to populate the right row in the description, or is this all high level what needs to be done?

Yes the tasks are getting created and assigning to the group (used run script to create tasks as system should check for application selected and for each row application each individual task should create).

- I just need to populate right row (mrvs variables: application name [reference], Env 1 [select box], env 2 [select box], additional info) values that belongs to each group task in task description.

Were you able to implement this solution to meet your requirements?

Hi Brad,

I am not able to populate still. How should I populate only rows (that belongs to an assignment group as each row contains an application selected which contains specific assignment group, the same group for each task) in catalog task description that has same assignment group as task group.