- 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
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
07-23-2020 11:33 AM
This seems to work, thank you for your assistance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 11:36 PM
You are welcome.
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
03-31-2021 05:54 AM
What if you need the value to change instantly visually for the user? Would writing the script as an onChange script do it? How would you write it that way? Thanks.