UsingIIF

From SMTX Wiki
Jump to navigation Jump to search

This is an example on how to use the IIF function in the form builder or within a workflow variable. The IIF function is defined like this:

 IIF (When arg1 true then return arg2, else return arg3)

In the example below, we want to validate if a value equals a certain string, when that is the case, I want to return the value 'Yes', otherwise 'No'

IIF ('#REPLACE-FORMFIELD-ValueToCheck#' = 'CheckedValue', 'Yes', 'No')

Please note the quotes around the text strings, but also around the internal label reference fields.

Another example : you want to check if a number (GETALa) is higher than 10

 IIF ('#REPLACE-FORMFIELD-playfieldform||GETALa||#' !=  && TONUMBER('#REPLACE-FORMFIELD-playfieldform||GETALa||#') > 10, 'Yes', 'No')

sidenote: field GETALa was a text field, so we need to use TONUMBER to make it a number. To avoid errors when the field is empty, we added the first part, that checks if it is different from empty.


The next example shows a more complex usage of the IIF function, in combination with other functions. We are now checking if a certain string exists within a given form answer. If it exists, we return 'Value1' if not, we check for another value and when that is found 'Value2' is return, otherwise 'NoValue' is returned.

IIF(INDEXOF('#REPLACE-FORMFIELD-ValueToCheck#','Value1Check') >= 0, 'Value1', IIF(INDEXOF('#REPLACE-FORMFIELD-ValueToCheck#','Value2Check') >= 0, 'Value2', 'NoValue'))

If you want to know if a number is between 10k and 100k

 IIF (ToNumber('#REPLACE-FORMFIELD-DANew||PrixTotal||#') <= 10000, 'below10k', IIF (ToNumber('#REPLACE-FORMFIELD-DANew||PrixTotal||#') > 100000, 'above 100k', 'between 10k and 100k'))