@If (Formula Language)

Evaluates a condition; if the condition is True, Notes/Domino performs the action appearing immediately after that condition, and stops. If the condition is False, Notes/Domino skips to the next condition and tests it, and so on. If none of the conditions is True, Notes/Domino performs the else_action.

Syntax

@If( condition1 ; action1 ; condition2 ; action2 ; ... ; condition99 ; action99 ; else_action )

Parameters

condition

Expression that returns a Boolean. If this expression returns True, action is performed. If it's False, Notes/Domino skips to the next condition, if there is one. Otherwise, Notes/Domino performs else_action.

action

An action to be performed or a value to be returned if the governing condition returns True.

else_action

An action to be performed or a value to be returned if none of the conditions returns True.

Usage

In its simplest form, the If statement looks like this: @If( condition ; action ; else_action ).

You can list up to 99 conditions and corresponding actions, followed by just one action to be performed when all the conditions are False. As soon as a condition evaluates to True, Notes/Domino performs the associated action and ignores the remainder of the @If statement.

Notes/Domino accepts the form @If( condition ), with only one condition and no action, but does not perform any action based on the condition.

If you compare a field to a value (for example, Year > 1995) and the field is unavailable, the comparison is False. However, you should check for fields that may not be present with @IsUnavailable.

Examples

  1. This formula tests the single value in the CostOfGoods field. If the value is greater than or equal to 12.45, the condition is True, and the string "Over Budget" is returned. If the value is less than 12.45, the condition is False and the string "Bill of Materials OK" is returned.
    @If(CostOfGoods>=12.45;"Over Budget";"Bill of Materials OK") 
  2. In this example, if CostOfGoods is less than 12.45, the null string is returned.
    @If(CostOfGoods>=12.45;"Over Budget";"")
  3. In this example, @If looks at the value in the CostOfGoods field; if the value is greater than 12.45, then the string "Over Budget" is returned; if not, Notes® skips to the next condition. The second condition also evaluates the CostOfGoods field and if the value is less than 12.45, then the condition is True and Notes® returns the string "Bill of Materials OK." If the value is neither greater than nor less than 12.45, Notes® moves on to the "else" action specified, and the string "Estimate Right on Target" is returned.
    @If(CostOfGoods>12.45;"Over Budget";CostOfGoods<12.45;
    "Bill of Materials OK";"Estimate Right on Target")
  4. Notes® first checks that the document has never been saved; if the condition is True, the value in the field NewNoteTitle is returned. If the first condition is False, Notes® then checks whether the view is the Author View; if this is True, the value in the field ByAuthorTitle is returned. If both conditions are False, the value in the field StandardTitle is returned.
    @If(@IsNewDoc; NewNoteTitle; @ViewTitle = 
    "Author View"; ByAuthorTitle; StandardTitle)
  5. This code, when used as the Input Validation for the phoneNumber field prohibits a form from being saved until the user enters a value in the phoneNumber field. This formula demonstrates how to test more than one statement, since a phone number is only required if the contactMe field is set to Yes, indicating that the user wants to be contacted.

    @If((contactMe="Yes") & (@ThisValue = "");@Failure("You must enter a value in " + @ThisName);@Success)

    Using @ThisValue and @ThisName instead of hard-coding in field names enables you to copy and paste this code into all the other fields you want to require input for, the firstName and lastName fields, for example.