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

You can just add lines like these to your Record Producer Script to do a straight 1 name-value pair entry for each MRVS variable.

var obj={};
var arr=[];
var mrvs = producer.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);
	obj['Date' + parseInt(i+1)] = row.v_date.toString();//replace with your date variable name
	obj['Incident/Details' + parseInt(i+1)] = row.v_details.toString();//replace with your details variable name
	arr.push(obj);
}
current.u_name_value = JSON.stringify(obj);//replace with your Name-Value Pair field name

 

Brad Bowman
Kilo Patron
Kilo Patron

It is clear from your results that you are using the script I posted, or at the very least you applied my object element naming convention to a non-working script, though I don't know why you would choose to put this in a separate Business Rule script, making it harder for others to find when they're investigating/modifying this functionality in the future. So who really provided the correct answer here?

Hi Brad, 

 

Actually both of your solutions worked for my case. I need something to display like this,could you please suggest me how can i achieve this?

find_real_file.png

My point was that you marked as a correct answer a script that does not work (due to the unique name restriction I pointed out in my initial response).  To populate the Name Value Pair using the alternative convention that I suggested, you just need to use this script instead in your Record Producer.

var obj={};
var arr=[];
var mrvs = producer.rp_mrvs;//replace with the internal name of your MRVS
var rowCount = mrvs.getRowCount();
for(var i=0;i<rowCount;i++){
	var row = mrvs.getRow(i);
	obj[row.v_date.toString()] = row.v_details.toString();//replace with your date and details variable names
	arr.push(obj);
}
current.u_mrvs = JSON.stringify(obj);//replace with your Name-Value Pair field name

This will work as long as every date entered into the MRVS is unique (which can be enforced when the MRVS is being populated and/or before the record producer is submitted).

Troya1
Mega Guru

Thank you so much for this Brad!  This is definitely a simpler solution to the MRVs question. 

We are having an issue with the Name showing up on the form.  It shows the sys_id instead of the display name of a user. 

 

find_real_file.png