Formula Language¶
The Validation Formula Language is used to validate or automatically populate fields based on values of other fields.
 Validation
 For example the Total amount in an invoice should be validated against the values of the Subtotal and the Tax amount. The formula would be
FT_TOTAL = FT_SUBTOTAL + FT_TAX
. The software will automatically validate the extracted data to make sure it is correct. Invalid fields are marked with a red frame to let you easily see and fix them. Hover over the field to see a tool tip with some more information about the error. The software will not let you export the data until all the data is valid.  Calculation
 We might want to automatically calculate and populate a field’s value if it is not present in a document, e.g.
FT_SUBTOTAL = FT_TOTAL  FT_TAX
To enter a formula for a field open the Form Definition Screen and put the formula in the Formula column. To refer to a field in a formula use the field’s ID. Field IDs are usually in all caps and start with FD_
like FD_TOTAL
but this is just a convention, you can use any character sequence.
Arithmetic Operators¶
The Validation Formula Language (VFL) of SmartSoft Invoices supports basic arithmetic operators. Complex validation rules can be built by combining these simple operators with predefined or custom functions.
List of supported arithmetic operators:¶
Operator  Description 

+  Addition  binary (requires two arguments) function: a + b 
  Subtraction  Binary or unary (one argument) function: a  b 
*  Multiplication  Binary function: a * b 
/  Division  Binary function: a / b 
Operations of addition, subtraction, multiplication and division correspond literally to their respective mathematical operators with standard priority.
Variables¶
There is integrated variable support in VFL for user defined variables accessible through the special variable lookup interface. Formulas with variables will be parsed and during the evaluation these variables will be replaced with their values returned by the variable lookup.
Variable names must start with a letter and can contain alphanumeric characters and the underscore symbol _
.
Colon symbol :
and pound symbol #
can be used for creating parametric variables.
Sample variable name: “FT_SUBTOTAL”.
Sample formula with variables: “FT_SUBTOTAL + FT_TAX”, “FT_GRANDTOTAL*0.20 + 1000”, etc.
Parametric variables¶
Parametric variables are used to apply one formula to all the cells in a table column. For each row the parameter will be replaced with the row’s index.
Sample parametric variable name: FT_LINE_TOTAL:#
Sample formula with parametric variables: FT_LINE_TOTAL:#  FT_LINE_DISCOUNT:# + 1000
.
The formula above will be converted automatically to FT_LINE_TOTAL:0  FT_LINE_DISCOUNT:0 + 1000
for the first row of the line item table and to FT_LINE_TOTAL:1  FT_LINE_DISCOUNT:1 + 1000
for the second row of the item table, and so on for the next rows.
Variable Names¶
Variable names can be constructed from uppercase and/or lowercase letters there are no restrictions, but keep in mind that during variable lookup the names are case sensitive. Most samples in this documentation use capital letters preceded by _FT
, like FT_TAX
, but this is just a convention.
Special variables¶
SELF
 Self reference in formula, this variable is replaced with the value of the field which is validated with the specified formula. For example we can use the following formula for the Grand Total field: IF(VAREXISTS(FT_TAX), FT_SUBTOTAL + FT_TAX, SELF)
. The formula above can be interpreted like this: If there is a value in the FT_TAX
field then the Grand Total field is populated with FT_SUBTOTAL + FT_TAX
, if there is no value in the FT_TAX
field then the Grand Total will not be calculated  its original value (SELF
) will be used for the field.
ERROR
 For specifying error conditions. Example formula for the Grand Total field: IF(VAREXISTS(FT_TAX), FT_SUBTOTAL + FT_TAX, ERROR)
. The formula above can be interpreted like this: If there is a value in the FT_TAX
field then the Grand Total field is populated with FT_SUBTOTAL + FT_TAX
, if there is no value in the FT_TAX
field then we cannot calculate the Grand Total field’s value and the result of the formula must be error (fail in evaluation).
Predefined Functions¶
The VFL supports wide range of predefined functions in different categories: arithmetic, logical, string manipulation, datetime, etc.
Function names are case insensitive  therefore the following names are equivalent: varexists
, VarExists
, VAREXISTS
.
Functions can be combined with variables and for maximum flexibility functions can be embedded in each other, for example: MIN(MIN(6,5),MAX(1,2),SUM(FT_TAX,3,SUM(2,3,5)))
.
The sample above can be written more clearly using scoped indentation like in programming languages:
MIN
(
MIN(6,5),
MAX(1,2),
SUM
(
FT_TAX,
3,
SUM(2,3,5)
)
)
Arithmetic functions¶
List of supported arithmetic functions:
Function  Description 

MIN  Returns the smallest of its arguments: MIN(2, 5, 8, 12) > 8 
MAX  Returns the largest of its arguments: MAX(2, 5, 8, 12) > 12 
SUM  Computes the sum of its arguments: SUM(1,2,3) > `` 6`` 
PRODUCT  Computes the product of its arguments: PRODUCT(2,2) > 4 
AVERAGE  Returns the average of its arguments: AVERAGE(5,6) > 5.5 
SIN  Computes the sine of its argument (degrees): SIN(90) > 1 
COS  Computes the cosine of its argument (degrees): COS(90) > 0 
SQRT  Computes the square root of its argument: SQRT(100) > 10 
POW  Computes the value of the first argument raised to the power specified with the second argument: POW(10, 2) > 100 
ROUND 

VARCOUNT 

Number of arguments:
 Functions
SIN
,COS
andSQRT
require only one argument  The power function
POW
requires exactly two arguments  the base and the exponent  Functions
MIN
,MAX
,SUM
,PRODUCT
andAVERAGE
can be used with variable number of arguments
Logical functions¶
Logical functions always return:
0
 logicalFALSE
value1
 logicalTRUE
value
List of supported logical functions:
Function  Description 

AND  Logical AND: AND(1,2,0) > 0 (FALSE) 
OR  Logical OR: OR(1,2,0) > 1 (TRUE) 
NOT  Logical NOT: NOT(1) > 0 (FALSE) 
EQ  Equality test function: EQ(2,2,2,2) > 0 (FALSE) , EQ(1,1,1) > 1 (TRUE) 
GREATER  Tests if the first argument is greater than the second argument: GREATER(3.25, 3.5) > 0 (FALSE) 
LESS  Tests if the first argument is less than the second argument: LESS(3.25, 3.5) > 1 (TRUE) 
GREATEREQ  Tests if the first argument is greater than or equal to the second argument: GREATEREQ(3.25, 3.25) > 1 (TRUE) 
LESSEQ  Tests if the first argument is less than or equal to the second argument: LESSEQ(3.25, 3.25) > 1 (TRUE) 
VAREXISTS  Tests if a given variable exists and can be retrieved using variable lookup VAREXISTS(VAR1) . Used to test whether a field has been populated or is empty. 
IF  Conditional operator function with following argument list:
Samples:

SWITCH  SWITCH allows conditional execution of statements with multiple choices. The first argument defines the value that will be tested. The rest of the arguments before the last one are the CASEs which test for a specific value of the condition. The last argument is DEFAULT which wraps the statement that will be executed if no CASE matched the first argument. Samples:
This will return “value is 5”.

CASE  CASE is used in SWITCH statements to perform statement execution when a specific condition is met. The first argument is the value that is compared with the SWITCH condition. The second argument is the statement that will be executed and the result will be returned from the SWITCH. Using CASE outside of a SWITCH will just execute the second argument and return the result, which is pointless. 
DEFAULT  DEFAULT wraps the execution of its argument and returns the result as if it were called without wrapping it in DEFAULT. The reason DEFAULT exists is to prevent putting a CASE as a last argument of SWITCH because this would make the formula confusing. This also makes it explicit. Using DEFAULT outside of a SWITCH will just execute its argument and return the result, which is pointless. 
SAME  SAME performs exact comparison of arguments and returns Example:

EQ  EQ performs loose comparison of arguments and returns 1 if the values of the arguments are the same and 0 if they are not, regardless of their types. Loose comparison means that if the second argument can be converted to the type of the first one they will be compared as values of the type of the first argument. The function may work with two or more arguments.

All logical functions can be combined with variables and other functions.
Number of arguments:
 the functions AND, OR and EQ can be used with variable number of arguments
 the functions NOT and VAREXISTS are oneargument functions, additionally VAREXISTS can be used only with variables as argument of the function
 the functions GREATER, LESS, GREATEREQ, LESSEQ are two argument functions
 the conditional operator function IF requires exactly 3 arguments as specified in the table above
String functions¶
The VFL of SSI supports string literals and variables with string values which can be used with functions specifically designed for strings.
String literals can be inserted in formulas in quotes  “sample string literal”.
List of supported string functions:
Function  Description 

STRCMP 

STRICMP  Same as the function above, but the string comparison is case insensitive. 
STRJOIN 

SUBSTR 

STRLEFT  
STRRIGHT 

SPLITGET 

SPLITGETREV 

STRCONTAINS 

STRLEN 

STRREPLACE 

STRUPPER 

STRLOWER 

STRUPPER  ("Fast Fox") > "fast fox" 
STRTRIM 

SPRINTF 

Regular Expression functions¶
Regular expressions can be used for searching and replacing in formula functions
List of supported regular expression fuctions.
Function  Description 

REGEXMATCH 

REGEXSEARCH 

REGEXSEARCHPOS 

REGEXREPLACE 

REGEXSPLIT 

REGEXSPLITGET 

Date functions¶
Functions that operate on dates accept string formatted with the following requirements:
 The date string must be exactly 8 symbols long
 The first 4 symbols are reserved for the year
 The next 2 symbols are reserved for the month  [1  12]
 The last 2 symbols are reserved for the day  [1  31]
 Sample date string:
2 June 2014
must be formatted as20140602
.
All date functions work correctly with leap years.
List of supported logical functions:
Function  Description 

DATEDIFFDAYS 

DATEDIFFMONTHS  Same as DATEDIFFDAYS, but the difference is calculated in months. 
DATEDIFFYEARS  Same as DATEDIFFDAYS, but the difference is calculated in years. 
DATEEQUAL 

DATEGREATER 

DATELESS 

MAKEDATE 

DATEADDDAYS 

TODAY  Creates a date initialized with the current day. 
Array functions¶
List of supported array functions:
Function  Description 

MAKEARRAY 

SPLIT 

JOIN 

ARRGET 

ARRCOUNT 

ARRCONTAINS 

ARRINDEXOF 

ARRUNIQUE 

ARRAVERAGE 

ARRMAX 

ARRMIN 

VARARRAY 

PROC 

FOR  Function for iterative execution of an operation. The function uses five arguments: Arg1 is the initialization block where the counter is initialized. Multiple variables initialization can be done with function PROC() Arg2 is Bool  the loop is repeated until this condition becomes true Arg3 is the operation which will be executed on every iteration Arg4 is used to increment the iterator Arg5 is the returned variable after all iterations are done Sample: FOR(PROC(@it=0, @fact=1), LESS(@it, 10), @fact=(@fact*(@it+1)), @it=(@it+1), @fact) > returns factorial of 10 
Address functions¶
List of supported functions for extraction of text from address(currently we support only USA addresses):
Function  Description 

ADDRGETSTATE 

ADDRGETCITY 

ADDRGETZIP 

ADDRGETSTREET 

ERP functions¶
List of supported ERP functions:
Function  Description 

SQLEXEC 

DBTYPE 

ERPEXEC  Alias for SQLEXEC 
Important
For dynamic lists for work properly AutoCalc, Calculable and DynamicList flags must be raised for that particular :ref:`field or column<flags_fields>.
Variable functions¶
List of supported variable functions:
Function  Description 

@variable 

Macros¶
Macros can be used in formulas in Verify. Click here to see supported macros in Verify.
Function  Description 

EVALEX  Displays the value of one or more applied macros. Autocalc flag must be applied for such fields. An example below shows a formula that displays the Batch Description and the document GUID value stored in the data base. EVALEXPR("$(BatchDesc)$(DocUuid)")
