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

In the original example, the 2 MRVS variables, v_date and v_details were date or string variables.  It looks like your variable is a reference field, so you can try row.variable_name.getDisplayValue().  If that doesn't work, then a quick GlideRecord query on the reference table to return the Name when given the sys_id will work.

getDisplayValue did not work. 

Can the GR query be added to the Record Producer script or does it have to be a Client Script? 

Sorry, I don't do must scripting and trying to find where to start with a GlideRecord query as well. 

Something like....

var gr = new GlideRecord('x_344184_finance_a_treasury');

gr.get(id);

var name = gr.getValue('employees_affected');

Something like that should work in the RP script in the For loop going through the MRVS, so id would be row.variable_name of this reference variable, then include name in the obj instead of the MRVS variable_name.

I think I may have goofed this up.  Trying to understand the logic

This is what I have and I'm still getting the sys_id in the name field on the form


var name={};
var arr=[];
var mrvs = producer.termination;//replaced with the internal name of your MRVS
var rowCount = mrvs.getRowCount();
for(var i=0;i<rowCount;i++){
var row = mrvs.getRow(i);
name[row.u_name] = row.date_need_access_terminated;//replace name field and date
arr.push(name);
current.employees_affected = JSON.stringify(name);//replaced with your Name-Value Pair field name
}