MRVS - How to transfer data between Catalog Item and MRVS on Service Portal - SOLVED

Filip Vojt__ek
Mega Guru

How to transfer data between Catalog Item and MRVS on Service Portal

 

First Create onLoad Client Script on Catalog Item with following code - Isolate script has to be false (needed only for first two use-cases)

 

function onLoad() {
	this.cat_g_form = g_form;
}

 


Let's understand MRVS triggers:

  • onLoad - When you click 'Add' button and MRVS form (modal) is loaded
  • onChange - as usual
  • onSubmit - When you click 'Add' to submit the row (and modal is closed)


Use-cases:

  • Set MRVS variable value based on catalog item variable value:
    Create a Client Script on MRVS (Isolate script has to be false) and set it onLoad, onChange or onSubmit according to your needs

 

if (this) {
	//Service Portal
	g_form.setValue('MRVS_variable_name', this.cat_g_form.getValue('cat_item_variable_name'));		
}

 

 

  • Set Catalog Item variable based on MRVS variable value:
    Create a Client Script on MRVS (Isolate script has to be false) and set it onLoad, onChange or onSubmit according to your needs

 

if (this) {
	//Service Portal
	this.cat_g_form.setValue('cat_item_variable_name', g_form.getValue('MRVS_variable_name'));		
}

 

 

  • Access data in MRVS from a Catalog Item:
    Create a Client Script on Catalog Item (Isolate script has to be false) and set it onLoad, onChange or onSubmit according to your needs (onLoad seems to make no sense)

 

var mrvsData = g_form.getValue('MRVS_name'); //MRVS data in string form of JSON	

var mrvsDataJSON = JSON.parse(mrvsData);
var count = 0;

for(var i in mrvsDataJSON) {
	if (mrvsDataJSON[i]['MRVS_variable_name'] == 'test')
		count++;
}

g_form.setValue('cat_item_variable_name', count);​

 

 

  • Update data in MRVS from a Catalog Item:
    Create a Client Script on Catalog Item (Isolate script has to be false) and set it onLoad, onChange or onSubmit according to your needs (onLoad seems to make no sense)

 

var mrvsData = g_form.getValue('MRVS_name'); //MRVS data in string form of JSON	

var mrvsDataJSON = JSON.parse(mrvsData);

for(var i in mrvsDataJSON) {
	mrvsDataJSON[i]['MRVS_variable_name'] = '5000';		
}

g_form.setValue('MRVS_name', JSON.stringify(mrvsDataJSON));

 

 

Credits goes to:

Michael Jones - 

Rupam5

 

Original article I've based this article on: 
https://www.servicenow.com/community/developer-articles/multi-row-variable-sets-how-to-get-or-set-va...

1 ACCEPTED SOLUTION

User656433
Kilo Expert

Thank you for a nice article. Really helpful!

View solution in original post

1 REPLY 1

User656433
Kilo Expert

Thank you for a nice article. Really helpful!