Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

How to calculate the sum of multiple fields

Avatar

Former Community Member
I have a form for this law firm I work for and I'm trying to make it so it will take the inputed value of multiple fields from multiple pages and find the sum and then display it into another field. I know how to write the FormCalc for fields on one page but, I don't know how to write the script/values for multiple pages to work. If anyone could help me that would be great!
6 Replies

Avatar

Former Community Member
I believe inorder to retrieve the values from other pages you must have the code running on server side. In the calculate event of the Total field have it add together all the fields from the other pages. Make sure the code is running on server side.



Dennis

Avatar

Former Community Member
Hi Nick,



You can do calculations for multiple pages client side by using invisible fields. Lets say you have 3 pages with the Grandtotal on the last page. For page 1 create a SubTotal1 field, with the calculation script that totals the fields on page 1. Copy this field over to page 3, setting the Default binding to "Global" and setting the Presence to "Invisible". Repeat for page 2. Page three now has 2 invisible fields on it. You can calculate your Grandtotal by adding the invisible fields (SubTotal1 & SubTotal2). Tip: check your work before making the fields invisible, so you can see if the values are being pushed successfully.



Hope this helps.



Pam

Avatar

Former Community Member
An even easier way is to name your pages. So for example, if you name your pages P1, P2, etc. then you can have a formcalc as simple as P1.field1 + P2.field1 + etc....

Avatar

Level 1

Scott,

Thank you so much for your post!

I have the same problem (6 page form, can calculate subtotals for each individual page, but cannot calculate grand total of all pages) and have been looking through a lot of content online. Most other solutions involved lots of scripting which I cannot understand or follow or tried to follow, and didn't work for me.

Your solution is so simple and clear to understand and worked great for me.

So again, THANK YOU for sharing your knowledge!!!!