How to get the calculations to show up on email or PDF

Hello all,
I’m doing a price calculator but I’m having some trouble to show the values in the email.

So far all seems to work inside the form, the price changes, values are shown in the summary etc., but once I send it, the email displays a “0” on all the calculations where I use the “SWITCH” function on both email summary or PDF.

If I do a summary using the “Pre-fill Key” for the calculation withing the form or in the success page it displays correctly, but not on the email.

Previously I was receiving a “null” value for all the “SWITCH” functions, until I realized i had to add a comma and a zero (as per one of the sample forms), with that the “Pre-fill Key” shows the value inside the form but the email displays the zeros instead of values.

This is what I currently have, but not sure if I’m doing something wrong with the formula :confused:, any input will be appreciated. Form here if you like to check it working

// Coefficient based on number of images - Start
baseprice = 10;
img3 = 10;
img4 = img3+10;
img5 = img3+20;

numimages = SWITCH ({{ 3n1te }},
"1", 10,
"2", 10,
"3", 10,
"4", 20,
"5", 30,
0);
// Coefficient based on number of images - End

//Structure coefficient
Structure = SWITCH({{ dep3b }},
"Simple", baseprice+numimages,
"Medium", baseprice+(2*numimages),
"Complex", baseprice+(3*numimages),
0);

// Environment variable
Environment = SWITCH({{ echi9 }},
"Simple", 1,
"Medium", 1.5,
"Detailed", 2,
0);

//Final formula
Structure*Environment

Hey, @Fredy.

The issue here is that the value on the frontend for the product is a bit different than the backend. So, your calculation works in the form directly but then breaks once it hits the server.

Namely, your products do not have identical answers on both. That is, a product of Medium is actually represented as Medium (Medium) on the server (format of Title (SKU)).

So, when your switch() looks for the specific values

  • Simple
  • Medium
  • Complex

it doesn’t find them since

Medium != Medium (Medium)

With a bit of regex, we can fix this up, though, so that the calculation effectively uses the same value on both the front- and backend.

Try replacing your calculation with

// Coefficient based on number of images - Start
baseprice = 10;
img3 = 10;
img4 = img3 + 10;
img5 = img3 + 20;

numimages = switch(numbervalue({{ 3n1te }}),
1, 10,
2, 10,
3, 10,
4, 20,
5, 30,
0);
// Coefficient based on number of images - End

// Structure coefficient
structure = trim(regexreplace({{ dep3b }}, "\\(.*", ""));
structure = switch(structure,
"Simple", baseprice + numimages,
"Medium", baseprice + (2 * numimages),
"Complex", baseprice + (3 * numimages),
0);

// Environment variable
environment = switch({{ echi9 }},
"Simple", 1,
"Medium", 1.5,
"Detailed", 2,
0);

// Final formula
structure * environment

Of additional note is that your numimages variable checks for selections of 1, 2, and 5 without those being possible options on the form currently. It doesn’t hurt anything, though. It’s just something to note.

Hope this helps!

1 Like

Hey Danny,
Awesome, thanks for the input and explanation!, I just updated my form and started to get the values. :grinning:.
Many thanks for fixing my formulas.

Thanks for pointing out the “numimages”.

1 Like