Formstack Documents is performing code updates to guarantee stability and security for our customers. The update took place on Nov 7, 2022, which could result in merge errors for specific cases. Below are the commonly returned errors:
- The Document Template contains math operations not supported by Formstack Documents
- The Document Template contains a division by zero as a denominator
- One or more Merge Fields are accessing object data on a non-object
1. The Document Template contains math operations not supported by Formstack Documents
The math operations performed contained incorrect data types. Typically, when attempting to subtract two values, at least one cannot be parsed as a numeric value.
For example:
{$number1 - $number2}
With values:
$number1 = ‘5’
$number2 = ‘test’
What action can I take?
Ensure all values that are passed into merge fields, that will be used in a mathematical operation, are numeric.
Copy calculations from an open-sourced word processor like TextEdit rather than from a program like Word to eliminate possible extra HTML properties.
Use the ‘intval’ or ‘floatval’ modifier to ensure the value is an integer or decimal (floating point) value.
Example:
{$number1|intval - $number2|intval}
2. The Document Template contains a division by zero as a denominator
The document contains a division operation, but the denominator is zero (0).
What action can I take?
Confirm that the data source never sends 0, empty, or null for any merge field that is used as the denominator for a division operation.
Use the |intval or |floatval modifiers to ensure the value is a numeric type.
Example:
{if $denominator|intval > 0}
{$numerator|intval / $denominator|intval}
{else}
0
{/if}
3. One or more Merge Fields are accessing object data on a non-object
An illegal array is offset with a string passed instead of an object in post data. An example of this could look like this:
{$Test[‘value’]} or {$Test.value}
With values:
$Test = ‘string’;
What action can I take?
Ensure all merge fields that will be used are passed in with the correct data structure. Use is_array to check that it is an array before accessing the value.
Example:{if is_array($MergeField)}
Populate data if array
{else}
Do something else if not array
{/if}
You can also convert the null value that is being sent over to an empty array by adding this line at the top of your document for each array:
{if !is_array($ExampleArray1)}{$ExampleArray1 = [“”]}{/if}
Example:
Another option is to do this through the Field Map option. To activate the Field Map, go to the Settings tab and click on the Advanced Settings menu on the right, and select the “Use Field Map for Custom Integrations” checkbox:
In this case, you should add the arrays at the top of your document as follows:
Single array example:
{if $ExampleArray1}{/if}
Multiple arrays example:
{if $ExampleArray1 && $ExampleArray2 && $ExampleArray3 && $ExampleArray4}{/if}
Example:
Then go to the Field map tab and add the if statement described above for each array.