Click or drag to resize
If

[This is preliminary documentation and is subject to change.]

The TOPICA Basic function If is used for conditional evaluation of expressions.

Syntax
If(conditionalExpression, thenExpression, elseExpression)
Parameters

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

Returns

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.

Example
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".

Remarks

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.

See Also