Calculated Fields
A field can be calculated based on dynamic values and other fields. When doing calculations on fields, you need to use JavaScript in place of the default value property. If you want to use the values from other fields in your calculation then use the field name (case sensitive) enclosed in curly braces - { and }. For instance, if you have 2 string fields you wish to concatenate - VAL1 and VAL2 - use this:
{{VAL1} {VAL2}}
This will result in a single string where the value from VAL1 is placed one space from the value in VAL2.
To do math with numbers, you can add operators to your value. For instance, if VAL1 and VAL2 are number values you can to this to add them together:
{{VAL1}+{VAL2}}
If you are doing math then you can also leverage some built-in functions:
cleanNumericValue(strValue) = This function will remove currency formatting characters and will treat a blank/null value as the number 0.
cleanDivision(val1, val2) = This function will not error out when using 0 in either value but will instead return a 0 value.
Combine the 2 numeric functions for truly safe computations:
{cleanDivision(cleanNumericValue(val1), cleanNumericValue(val2)) }
Supported Custom Functions:
String Functions
replaceAll(instr, find, replace)
- Replaces all instances of find with replace in instr
stringContains(instr, containsStr, yesval, noval)
- Returns true or yesvall if "instr" contains containsStr and false or noval if not
- This function is NOT case sensitive
USE: To see if 2 fields are filled in use {stringContains('~{field1}~{field2}~', '~~', 'yes', 'no')} equals no.
stringLength(instr)
- Returns the length of the string
Number Functions
getNumValue (instr)
- If "instr" is a number then it is returned. If not, instr is sent into cleanNumericValue function to be cleaned to a number
cleanNumericValue (instr)
- Removes all non-numeric characters from the incoming string
cleanDivision(val1, val2)
- Divides val1 by val2 and if either value is null, 0 or non-numeric, it returns 0
tryParseFloat(value, default)
- Tries to convert value to floating point number and if it cannot then it returns the default value
getFormattedNumber(value, places)
- Formats the incoming value as a number with the specified number of decimal places
formatCurrency(value, places)
- Formats the value using USD currency formatting
calcSum(Values, Delimiter)
- Calculates the Sum of the values in the incoming string
- Values - The string that has the values to calculate. Must be delimited by a specific character.
- Delimiter - The character to split the Values string on to get the numbers. Default is ^ because using the {Table| |Column} syntax returns values separated by ^.
- Examples:
- {calcSum(1^2^3,^)} = 6
- {calcSum(1^2^3)} = 6 (works since default delimiter is ^)
calcAvg(Values, Delimiter)
- Calculates the Average of the values in the incoming string
calcMax(Values, Delimiter)
- Calculates the Maximum of the values in the incoming string
calcMin(Values, Delimiter)
- Calculates the Minimum of the values in the incoming string
calcCount(Values, Delimiter)
- Calculates the Count of the values in the incoming string
Date Functions
dateDiff(datefrom, dateto, interval)
- Computes the number of intervals between datefrom and dateto. Allowed “interval” values are:
- s, sec, second, seconds – Number of seconds
- n, min, minute, minutes – Number of minutes
- h, hour, hours – Number of hours
- d, day, days – Number of days
- m, mon, mons, month, months – Number of months
- y, yr, year, years – Number of years
timeDiff(timefrom, timeto, interval)
- Computes the number of intervals between timefrom and timeto. Allowed “interval” values are:
- m – Number of minutes
- h – Number of hours
- Anything else returns a string formatted as HH:MM
formatTime(hours, minutes, seconds)
- Returns a date formatted using h:m:s format
IMPORTANT NOTE: Be sure to use { and } around any text that need calculated! It may work without them now but in a future release we will only be calculating inside the { and }.
To get the AMOUNT value from Radio Buttons and Option Lists you can use the {FIELDNAME:AMOUNT} pattern. For instance, if an option list named "DeliveryCharge" has Amount values, you can get those amounts using {DeliveryCharge:Amount}.
IMPORTANT NOTE ABOUT USING COMPUTED VALUES IN SAVED FIELDS
If you want to compute a value in a field type that saves data (i.e. Text, Text Area, Number, etc.) then you need to make sure to set its "Data" / "Where to Get Initial/Latest Value" option to "Do Not Set Value / Compute Value" otherwise the computation will be lost while generating a new form or using the Use Latest Template options.