- 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
03-31-2021 06:02 AM
Hi,
you can try creating onChange on that variable within MRVS
check these links on how to access the variables outside the MRVS inside your script
https://community.servicenow.com/community?id=community_question&sys_id=84c17148db791c5014d6fb24399619bc
https://community.servicenow.com/community?id=community_question&sys_id=def61f32dbf5dc102e8c2183ca961951
https://community.servicenow.com/community?id=community_question&sys_id=a3d51cb7dbe8ac10a08a1ea66896199f
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
05-14-2021 10:22 AM
Hi Ankur,
I'm not sure why this is not working for me.
I have 2 fields in MRVS, the name of the item and the amount to be deducted.
I used your code, however, the Total Deduction Amount amount field is not getting populated by the sum of the Deduction Amount field
Here is my script
function onSubmit() {
//Type appropriate comment here, and begin script below
var value = g_form.getValue('u_deduction_amount'); // 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].u_deduction_amount); // give here variable name inside MRVS
}
g_form.setValue('total_deduction_amount', sum); // give here the proper variable name here
}
Your help on this will be much appreciated. Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2021 11:18 PM
Hi,
did you alert what came in the sum?
Also is the mrvs variable name correct for u_decuction_amount
Seems the name of MRVS variable set is also not correct?
function onSubmit() {
//Type appropriate comment here, and begin script below
var value = g_form.getValue('u_deduction_amount'); // MRVS variable set name here
var parser = JSON.parse(value);
var sum = 0;
for (var i = 0; i < parser.length; i++) {
sum = sum + parseFloat(parser[i].u_deduction_amount); // give here variable name inside MRVS
}
g_form.setValue('total_deduction_amount', 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
06-28-2022 09:02 AM
Hi Ankur,
Can we also do it for SRVS ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 08:30 AM