If

Use an If block to run a set of tasks only when a condition is met.

The If task evaluates an IronPython condition script. The script must set the result variable to True or False:

  • If result is True, the tasks inside the block run.
  • If result is False, the tasks inside the block are skipped and the job continues with the first task after End If. When an Else section is present, the else section runs instead.

The condition script can use field variables (for example {documentProperty:Region} or {forEachProperty:Country}). The variables are replaced with their values before the condition is evaluated.

You can add an Else task inside the If block to divide it into two sections: one that runs when the condition is true and one that runs when it is false. Each If block can contain a maximum of one Else task.

You can insert a Break or an Exit task inside an If block.

You can nest If blocks inside ForEach loops and other If blocks to any depth. For more information, see Nested blocks.

Examples of condition scripts

Run the If block only when the document property RowCount is greater than zero:

result = AutomationContext.Application.Document.Properties["RowCount"] > 0

Use a field variable inside a ForEach loop to skip rows where the country is "Unknown":

result = "{forEachProperty:Country}" != "Unknown"

Check a string document property:

result = AutomationContext.Application.Document.Properties["Region"] == "EMEA"