How to access multi row variable set in client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2019 08:30 AM
Hello All,
I want to compare MVRS 1st row fields data with 2nd & 3rd etc Row fields data, How could be possible, I have tried with below scripts but didn't get an expected result
function onLoad() {
//Type appropriate comment here, and begin script below
var mrvs = JSON.parse(g_form.getValue('variables.asset_details_and_costing_info'));
alert(mrvs.length);
alert(mrvs);
alert(mrvs[0].asset_type_requisition);
alert(mrvs.asset_type_requisition);
JSON.stringify(mrvs);
alert(mrvs.length);
alert(mrvs[1].asset_type_requisition);
alert(mrvs.asset_type_requisition);
var mrvs1 = JSON.parse(g_form.getValue('asset_details_and_costing_info'));
var getPrio = mrvs.map(function (mrvs1) {
return mrvs1.asset_type_requisition;
});
alert('array of priority ' + getPrio);
function dedup(arr) {
var servers = [];
var returnArr = arr.filter(function(row){
if(servers.indexOf(row.question_1)<0){
servers.push(row.question_1);
return row;
} else {
// row already entered
//console.log('row already exists with that variable');
}
});
return returnArr;
}
//console.log(JSON.parse(g_form.getValue("multirow_variable_set")));
console.log(g_form.getValue("asset_details_and_costing_info"));
var deduped = dedup(JSON.parse(g_form.getValue("asset_details_and_costing_info")));
console.log(deduped); // [ {a: 1}, [1, 2] ]
g_form.setValue("asset_details_and_costing_info",JSON.stringify(deduped));
}
I want to compare Asset Type row 1 data with row2 data, if both are not equal I want to show pop message to the end user saying that,
Please select same Asset Type for all rows
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2019 12:30 AM
Hi Rajesh,
My query is not yet resolved, My question is I want to compare 1st row data with second row data on the fly, if asset type is mismatch in two rows I want to remove second and show popup message saying that "please select same asset type" in all rows, Please send me the code I have written below codes but no luck.
function onLoad() {
//Type appropriate comment here, and begin script below
var mrvs = JSON.parse(g_form.getValue('variables.asset_details_and_costing_info'));
alert(mrvs.length);
alert(mrvs);
alert(mrvs[0].asset_type_requisition);
alert(mrvs.asset_type_requisition);
JSON.stringify(mrvs);
alert(mrvs.length);
alert(mrvs[1].asset_type_requisition);
alert(mrvs.asset_type_requisition);
var mrvs1 = JSON.parse(g_form.getValue('asset_details_and_costing_info'));
var getPrio = mrvs.map(function (mrvs1) {
return mrvs1.asset_type_requisition;
});
alert('array of priority ' + getPrio);
function dedup(arr) {
var servers = [];
var returnArr = arr.filter(function(row){
if(servers.indexOf(row.question_1)<0){
servers.push(row.question_1);
return row;
} else {
// row already entered
//console.log('row already exists with that variable');
}
});
return returnArr;
}
//console.log(JSON.parse(g_form.getValue("multirow_variable_set")));
console.log(g_form.getValue("asset_details_and_costing_info"));
var deduped = dedup(JSON.parse(g_form.getValue("asset_details_and_costing_info")));
console.log(deduped); // [ {a: 1}, [1, 2] ]
g_form.setValue("asset_details_and_costing_info",JSON.stringify(deduped));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 09:08 AM
Hi there,
Just found a way today to access the Multi Row Variable Set, Client Side.
Have a look at:
https://community.servicenow.com/community?id=community_article&sys_id=2a508caedbf47f48d82ffb2439961...
It's all about using:
g_form.getValue("IO:0c031f8ddb74bfc4d82ffb2439961984");
(just replace the sys_id with your actual Multi Row Variable Set sys_id)
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2021 12:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 02:49 AM
Shantharao, Did you get this issue solve?