- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I created a new record producer that generate record in sn_slm_task table.
Inside this record producer i added a Multi Row Variable Sets.
Is there any way to access this MVRS values using the producer script on the sc_cat_item_producer record?
using this script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Alon Grod
You Can Parse the Variable ,
Lets Say for Example
if variable name is requested_items and it has name and Quantity
The Script Can be Similar as
var mrvs = producer.requested_items;
if (mrvs)
{
var rows = JSON.parse(mrvs);
for (var i = 0; i < rows.length; i++)
{
gs.info('Item: ' + rows[i].item_name);
gs.info('Quantity: ' + rows[i].quantity);
}
}
Output can be similar as
[
{
"item_name": "Laptop",
"quantity": "2",
"description": "Developer laptop"
},
{
"item_name": "Monitor",
"quantity": "3",
"description": "External monitors"
}
]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Alon Grod
You Can Parse the Variable ,
Lets Say for Example
if variable name is requested_items and it has name and Quantity
The Script Can be Similar as
var mrvs = producer.requested_items;
if (mrvs)
{
var rows = JSON.parse(mrvs);
for (var i = 0; i < rows.length; i++)
{
gs.info('Item: ' + rows[i].item_name);
gs.info('Quantity: ' + rows[i].quantity);
}
}
Output can be similar as
[
{
"item_name": "Laptop",
"quantity": "2",
"description": "Developer laptop"
},
{
"item_name": "Monitor",
"quantity": "3",
"description": "External monitors"
}
]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Alon Grod ,
Use this script :
checkRedirect();
function checkRedirect() {
// Your existing redirect logic
}
var bb = new GlideRecord('item_option_new');
bb.addEncodedQuery('cat_item=4016a1a1...^name!=hash'); // Your existing query
bb.query();
while (bb.next()) {
var variableName = bb.getValue('name');
var val = producer[variableName];
if (val) {
// 1. CHECK IF THE VARIABLE IS A STRINGIFIED MRVS OBJECT
if (typeof val === 'string' && val.indexOf('[{"') === 0) {
try {
var mrvsArray = JSON.parse(val);
// Loop through the MRVS rows
for (var i = 0; i < mrvsArray.length; i++) {
var mrvsRow = mrvsArray[i];
// Access individual columns within the MRVS row
// var rowValue = mrvsRow.your_mrvs_column_name;
}
} catch (e) {
gs.error("Failed to parse MRVS: " + e.message);
}
} else {
// 2. STANDARD VARIABLE LOGIC (Your existing mapping code)
/*
var gr = new GlideRecord('question_answer');
...
*/
}
}
}
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You,
Sujit Jadhav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what's your actual requirement?
in record producer script you can access that MRVS using this syntax and it will give you JSON string
producer.mrvsVariableSetName
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Alon Grod,
For Example, there is multi row variable set named Task Details mrvs (internal name: task_details_mrvs)
In your Record Producer script you can get your array of variable set variable values for each row.
Parse and loop through each row, get each variable value for that row with it’s name.
Iam setting the description of incident with each row variables.
Script:
(function() {
var mrvsRaw = producer.task_details_mrvs;//give your multi row variable set internal name
// Parse the JSON string into a JavaScript array
var rows = JSON.parse(mrvsRaw);
var formattedOutput = '';
//Loop through the array rows
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
formattedOutput += 'Row ' + (i + 1) + ':\n';
formattedOutput += ' Short Description: ' + row.task_short_desc + '\n';
formattedOutput += ' Description: ' + row.task_desc + '\n\n';
}
//Set fields on the incident record
current.short_description = 'Incident created via MRVS';
current.description = formattedOutput;
})();
I created two rows with sample values and after submission , I get the each row values in the description as shown below.
