We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to access multi row variable set in client script?

Shantharao
Kilo Sage

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));

}

 

 

find_real_file.png

 

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

8 REPLIES 8

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 Roethof
Tera Patron

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi, I am trying to access/set fileds in MRVS mandatory using onchange cs based on field value present on the item. Could you please assist. I am writing on change on item. Var mr=g_form.getValue('IO:mrvs_sysid'); g_form.setMandatory(mr.mrvs_field_name,'true'); Not working

ShubhamGarg
Kilo Sage

Shantharao, Did you get this issue solve?