How to map multi row variable set from record producer to case form

Renu9
Tera Contributor

How to create multi row variable set in the case form. It has to be with 3 columns and n number of rows on addition. 

Could anyone please suggest how it can be created in case UI .

1 ACCEPTED SOLUTION

@Renu 

You can use this script in before insert BR of Case Table

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

	// Add your code here

var mrvs = current.variables.mrvs; // your MRVS variable name here

var arr = [];

var parser = new global.JSON();
var parsedData = parser.decode(mrvs);

for(var i=0;i<parserData.length;i++){

var obj = {};
obj['Date'] = parsedData[i].date.toString(); // give here the mrvs variable name of date
obj['Incident Details'] = parsedData[i].incident_details; // give here the mrvs variable name of incident_details
arr.push(obj);

}

current.setValue('u_name_value', JSON.stringify(obj)); // your Name-Value field name here

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

28 REPLIES 28

OK, we'll get there.  This example assumes u_name is the name of a MRVS variable of the reference type.  First try this if you haven't already.

var name = {};
var arr = [];
var mrvs = producer.termination; 
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
    var row = mrvs.getRow(i);
    name[row.u_name.getDisplayValue()] = row.date_need_access_terminated;
    arr.push(name);
    current.employees_affected = JSON.stringify(name); 
}

If that doesn't do anything, causes an error, or still shows the sys_id, we can add a GlideRecord query.  Assuming the reference table on this variable is x_344184_finance_a_treasury, and there's a field named emp_name on that table which holds the value to be displayed instead of the sys_id, your script would look like this.

var name = {};
var arr = [];
var mrvs = producer.termination; 
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
    var row = mrvs.getRow(i);
	var gr = new GlideRecord('x_344184_finance_a_treasury');
	if(gr.get(row.u_name)){
		name[gr.emp_name] = row.date_need_access_terminated;
		arr.push(name);
		current.employees_affected = JSON.stringify(name); 
	}
}

I think the last line may be causing the issue.  

employees_affected = name of the Name-Value Pair field on form

var name = {};
var arr = [];
var mrvs = producer.termination; 
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
    var row = mrvs.getRow(i);
	var gr = new GlideRecord('x_344184_finance_a_treasury');
	if(gr.get(row.u_name)){
		name[gr.emp_name] = row.date_need_access_terminated;
		arr.push(name);
		current.employees_affected = JSON.stringify(name); 
	}
}

@Brad Bowman  I appreciate the help.  Do you have any additional suggestions based on my above response?

David Neustadt1
Tera Contributor

Having this same issue: 

 

I have a MRVS on a record producer that I want the values added to map to the description field on the resulting HR case record. Below is an example of my MRVS with the fields that values are entered for. 

The 2 variables in my MRVS are 'state' and 'allocation_percentage'

I tried using this UI Policy OnCondition script on the record producer but it did not work

function onCondition() {
var varName = JSON.parse(producer.state_withholding_elections);
var description = '';
for (var i = 0; i < varName.length; i++) {
description += "\n state: " + varName[i].state + "\n allocation_percentage: " + varName[i].allocation_percentage + "\n";
}
current.case_field = description;

}