- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2021 05:45 AM
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 .
Solved! Go to Solution.
- Labels:
-
HR Service Delivery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2021 07:25 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 03:45 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 03:55 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 04:01 PM
Something like....
var gr = new GlideRecord('x_344184_finance_a_treasury');
gr.get(id);
var name = gr.getValue('employees_affected');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2021 03:48 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2021 11:05 AM
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
}