- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 09:00 AM
Is there a way to calculate a total from values in rows in a multi-row variable set (mrvs) into a variable outside of the mrvs on a catalog item?
Use-case that I have is a user is entering in various tuition expenses in each row of the mrvs, and those entries are totaled in the last column of that row entry (e.g. books + fees + tuition = total cost). They can enter this information in for multiple classes via the mrvs. As they are entering in the various rows I'd like to update a 'grand total' field on the record producer that is the sum of the 'total cost' in each row of the mrvs.
The Docs site states: "Scripts that are not included in a multi-row variable set cannot affect variables inside the multi-row variable set. Similarly, the scripts included in the multi-row variable set cannot affect the variables that are not included in the multi-row variable set."
I'm just curious if anyone else has found a way to make this work or if I need to do away with the mrvs and use variables on the record producer.
Thanks
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 09:01 AM
Hi,
you will have to write onSubmit client script and parse the json and set the value by summing up the values
Sample script below
function onSubmit(){
var value = g_form.getValue('mrvs_variable name'); // your MRVS variable name here
var parser = JSON.parse(value);
var sum = 0;
for(var i=0;i<parser.length;i++){
sum = sum + parseFloat(parser[i].estimated_total_cost); // give here variable name inside MRVS
}
g_form.setValue('course_subtotal', sum); // give here the proper variable name here
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 08:24 AM
Hi,
The value is not auto-populated, if that's what you ask. But upon submission, you can see that actually the value is populated.
Having said that, have you found a way to auto-populate the total deduction amount?
Thanks!
Best,
Firat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 03:59 AM
hello Sir , what should be the type of variable which is outside MRVS ,(in which we want to display the total sum value) ?