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

Hi Ankur,

I know this answer is pretty old, was wondering if you could help me out here. I am using the above code for blow JSON:

[ {
"mrvs_training_type" : "Standard PST/SLT",
"mrvs_preset_description_needed" : "Yes",
"mrvs_preset_description" : "25 IMV Training",
"mrvs_document_or_meeting_date" : "2022-05-19",
"mrvs_duration" : "00:15:00",
"mrvs_training_documents" : "www.test3.com"
}, {
"mrvs_training_type" : "Standard PST/SLT",
"mrvs_preset_description_needed" : "Yes",
"mrvs_preset_description" : "16 TMF Specifications",
"mrvs_document_or_meeting_date" : "2022-04-11",
"mrvs_duration" : "00:10:00",
"mrvs_training_documents" : "www.test3.com"
}, {
"mrvs_training_type" : "Standard PST/SLT",
"mrvs_preset_description_needed" : "No",
"enter_training_description" : "Samples Gathering Instructions",
"mrvs_document_or_meeting_date" : "2022-05-02",
"mrvs_duration" : "00:40:00",
"mrvs_training_documents" : "www.test3.com"
} ]

 

But JSON.stringify(obj), only stores value of last array from above 3. can you please help me so that object has all3 values and I can populate the same on my form.

@MK 

Can you post this as separate question and tag me there?

Please share all the relevant details, scripts and screenshots

Regards
Ankur

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

Is it possible to have more than two columns from the MRV?

Brad Bowman
Kilo Patron
Kilo Patron

Hi Renu,

The multi row variable set is limited to record producers, order guides, and catalog items that use variables.  The exact same functionality does not exist as a field type to add to any table or form.  If you are populating x columns and y number of rows on a MRVS in a record producer, and don't have specific fields on the case form to map each MRVS variable to, you have (at least) 2 options to view this data in one field on the case form.

1) Copy the MRVS contents into a String field.  The result would look something like this

find_real_file.png

In the script while copying the values you could also remove the brackets and quotes to make it a bit more readable.

find_real_file.png

2) Copy the MRVS contents into a Name-Value Pairs field.  The result would look like this on the form.

find_real_file.png

The numbers at the end of names corresponding to the row number from the MRVS are due to the restriction that Name in a Name-Value Pair has to be unique.  If you only have the 2 columns, you could also use the Date column as the Name, if it will always be unique per row, so that it looks more like this.

find_real_file.png

 

 

Hi Brad,

Could you please help in letting know how you copied the MVRS contents into name- value pairs field.