if

Perform an action on a data extract if a condition is false.

This guide explains how to configure the if instruction. To learn about another instruction, go back to the Available custom script instructions overview.

Introduction

Use the if instruction to perform an action on the data extract if the condition of an expression is false. Use the Complement field to reverse the condition so the action is performed if the expression is true.

The actions available include raising errors, notifying users and removing data. Enter the expression as a Python expression. For more information on what you can enter as a python expression, see Using Python expressions in custom scripts.

Creating a custom script transformation using the if instruction

To create and configure a custom script using the if instruction, follow these steps:

  1. Create a custom script transformation.

  2. In the Instructions step, select the if instruction.

  3. To configure the custom script instruction, fill in the following fields. Required fields are marked with an asterisk (*).

Condition*

Enter a python expression. If the outcome of the expression is false, an action is applied to the data extract. For more information on what you can enter as a python expression, see Using Python expressions in custom scripts.

Action

Select one of the following actions:

Remove

If the expression is false, the entire data extract is removed.

Raise

If the expression is false, an error is added to the transformation logs and a message is displayed on screen.

Notify

If the expression is false, an error is sent to the user as a notification. This notification is sent to users that are subscribed to the Transformation Error topic. For more information on notifications, see Managing user notifications.

Break

If the expression is false, the data extract is split. All rows above the row where the expression equals false are kept, and the remaining rows in the data extract are removed.

Message

Enter the message to display or notify users when the condition is met.

Complement

Select this field to reverse the expression and the action is taken if the expression is true.

Subtable

Enter the name for a subtable that you want to use within this custom script.

A subtable is a temporary table that only exists for this custom script. You can apply additional instructions within the same custom script to the subtable. However, the subtable cannot be used in any other custom scripts.

If a subtable does not exist for the current custom script, the transformation is applied to the data extract, and the enriched data is output into the subtable. If the subtable already exists for the custom script, the subtable is used as the input for the transformation and optionally as the output.

For the if transformation the subtable is used as the input only.

Example

To notify users if there have been no conversions in a data extract, use the following transformation configuration for the if transformation.

Transformation configuration

Condition

{total_conversion} == '0'

Action

notify

Message

'There have been no conversions'

Complement

Select this field to ensure the notification is sent. As the transformation runs when the if statement is FALSE, the Complement field needs to be selected so that when the condition is TRUE, it is reversed to FALSE.