Calculated field - runtime Add concatenates two numbers instead of add numeric value when one value comes from choice (dropdown) field. Calculated field formula (dropdown value =10) + 5 returns 105 instead of 15. Mul, Div, and Sub functions calculate correctly. I am running latest 2019 Nintex Forms on premise.
This is likely because of what's known as "Type Coercion". The first value from your dropdown is probably a string, and because of that, when it tries to add:
"10" + 5
It first sees a string, and then attempts to "coerce" the number 5 into the same type. Because in JavaScript, the "+" operator means to "add" numeric values but is ALSO shorthand for string concatenation, it simply treats the entire operation like a string concat and places the two together.
To fix this, you can place the dropdown value inside of another function called 'parseInt()' as follows:
Add(parseInt({dropdown}, 10), 5)
/* or alternatively */
parseInt({dropdown}, 10) + 5
(Note: You may have noticed that there is a "10" thrown inside of that parseInt function. That's the radix or "base" of the number system js is going to use to determine what the value should output as. It's incredibly important that you leave it set to 10 as we live in a Base Ten kinda world. Leaving it blank or changing the value to a different base will result in your numbers being wrong!
For more information, please see: MDN: parseInt)
If you need any further help with this topic, feel free to yell.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.