- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-30-2022 10:35 PM
I'm unable to retrieve MRVS data from onsumbit client script. I have a requirement to get the total value of seats into a variable outside of MRVS. I'm using on submit client script.
Below is the code which I tried
function onSubmit() {
var gr = g_form.getValue(#varibale set name);
var parser = JSON.parse(gr);
var sum = 0;
alert(parser);for(var i=0;i<parser.length;i++){
sum = sum + parseFloat(parser[i].seats); // variable name inside MRVS
alert(sum);
}
I'm getting gr value as empty and the total field is also not updating. Please help me in getting the total value into a variable outside of the multi row variable set.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2022 12:05 AM
Hi Author,
To access the outside variables do the below
First, You would need to create an Onload script in your catalog item, with isolate script set to false:
function onLoad() {
//We need to make the g_form object for the parent item available for later
this.cat_g_form = g_form;
}
Once that is in place, you can use something like in a script on the MVRS (also set to isolate script false).
function onSubmit() {
//Type appropriate comment here, and begin script below
var multiRowVariableSet = JSON.parse(g_form.getValue('demo_variable_set')); // Replace your variable set Name and not label here.
var totalCost = 0;
for (var i = 0; i < multiRowVariableSet.length; i++) {
totalCost += multiRowVariableSet[i].Variable_Name; //add all totals from the MRVS to 1 total
}
alert(totalCost);
//Service Portal logic
if (this) {
this.cat_g_form.setValue('variable_name', 'totalCost');
} else {
//Native UI logic
parent.g_form.setValue('variable_name', 'totalCost');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2022 01:05 AM
Any update on my post above?
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2022 12:05 AM
Hi Author,
To access the outside variables do the below
First, You would need to create an Onload script in your catalog item, with isolate script set to false:
function onLoad() {
//We need to make the g_form object for the parent item available for later
this.cat_g_form = g_form;
}
Once that is in place, you can use something like in a script on the MVRS (also set to isolate script false).
function onSubmit() {
//Type appropriate comment here, and begin script below
var multiRowVariableSet = JSON.parse(g_form.getValue('demo_variable_set')); // Replace your variable set Name and not label here.
var totalCost = 0;
for (var i = 0; i < multiRowVariableSet.length; i++) {
totalCost += multiRowVariableSet[i].Variable_Name; //add all totals from the MRVS to 1 total
}
alert(totalCost);
//Service Portal logic
if (this) {
this.cat_g_form.setValue('variable_name', 'totalCost');
} else {
//Native UI logic
parent.g_form.setValue('variable_name', 'totalCost');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2022 01:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2022 03:46 AM
Thanks a Lot! It worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2022 09:00 PM