Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2022 06:38 AM
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:
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...
Solved! Go to Solution.
- 1,982 Views
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 01:16 AM
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 01:16 AM
Thank you for a nice article. Really helpful!