- 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
03-15-2021 08:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2021 04:06 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2021 08:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2021 09:12 AM
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).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 03:34 PM