If |
[This is preliminary documentation and is subject to change.]
The TOPICA Basic function If is used for conditional evaluation of expressions.
If(conditionalExpression, thenExpression, elseExpression)
Name | Type | Description |
---|---|---|
conditionalExpression | Boolean | Expression |
thenExpression | Any | Result of function when conditionalExpression evaluates to true |
elseExpression | Any | Result of function when conditionalExpression evaluates to false |
Evaluated value of thenExpression or elseExpression, dependent on the value of conditionalExpression.
The type of the return value is the type of thenExpression or elseExpression, dependent on the value of conditionalExpression.
If (2+2=4, "2 plus 2 equals 4", "2 plus 2 does NOT equal 4")
This expression will return the string value "2 plus 2 equals 4".
If uses "short-circuit" evaluation. This means:
If conditionalExpression evaluates to true, only the thenExpression expression is evaluated the elseExpression expression is NOT evaluated.
If conditionalExpression evaluates to false, only the elseExpression expression is evaluated the thenExpression expression is NOT evaluated.
This for example makes it possible to use If to test for null objects before accessing properties:
If(IsNull(Record.UpdatedBy), "Record never updated", "Record last updated by: " + Record.UpdatedBy.Username + " " + Record.UpdatedBy.Firstname + " " + Record.UpdatedBy.Lastname)
When accessing properties on an object, that may be null, it is important to check for null first. In "strict" mode, the system will throw an exception when accessing properties on a null object.