WEBcnx 2024.1 is out now bringing with it a host of new features and performance enhancements. Read more.

Open navigation

IF Function

Applies from Version:WEBcnx 2024.1Applies to Version:


Description

The IF function analyses its first parameter whether it evaluates to true or false, and then - based on these findings - returns either its second or third parameter.


Syntax 

IF(condition, trueResult, falseResult)


The IF function has the following arguments:

  • condition Required. A boolean expression that we wish to evaluate
  • trueResult Required. The desired result if condition resolves to true
  • falseResult Required. The desired result if condition resolves to false

This function takes three parameters. The first one must be a Boolean, the other two can be of any type

Returns

There is no fixed return type for the IF statement, it will always return either trueResult or falseResult, but these can be of any type.


Remarks

  1. If trueResult or falseResult is a System type with an Api equivalent, it will be converted and returned as the corresponding Api type. For instance, providing System.String will yield Api.String as the result.
  2. trueResult and falseResult need not be simple data. We can, for example, declare other IF functions as these parameters to create nested functions.


Examples

Imagine we have two distance fields in an Item Type, with the identifiers Height and Width.

ExpressionDescriptionResult
IF(4 > 2, "Four", "Two")Checks if 4 is bigger than 2"Four"
IF(Height > Width, "Portrait", "Landscape")Determines whether we have a Portrait or Landscape orientation"Portrait" if Height is greater than Width, "Landscape" if not
IF(Height > Width, "Portrait", IF(Width > Height, "Landscape", "Square"))As above, but a nested function that returns Square if Width and Height are the same"Portrait" if Height is greater than Width

"Landscape" if Width is greater than Height

"Square" if Width equals Height


Further Reading

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

You may like to read -