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:
IF(logical_test, value_if_true, value_if_false)
First the first argument logical_test expression is evaluated.
If the result of this evaluation is logical TRUE , then the second argument value_if_true
is evaluated and the result of this evaluation is returned.
If the result of logical_test is logical FALSE , then the third argument value_if_false
is evaluated and the result of this evaluation is returned.
Samples:
IF(LESS(1, 2), 1+2, 12) > 3 (the result of 1+2)
IF(NOT(LESS(1, 2)), 1+2, 12) > 1 (the result of 12)
IF(NOT(VAREXISTS(FT_TAX)), FT_SUBTOTAL * 0.2, SELF) 
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 

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)")
