Dynamic Rule Activation Using Custom Parameters

Overview

This guide describes how to use a Custom Parameter of an Entity Copy Task inside the Activation Script of an Entity Modification Rule.

In this example, a Custom Parameter is used to control whether an Entity Modification Rule is activated.

The Custom Parameter is called activateRule and has the default value false.

  • If activateRule is false, the Entity Modification Rule is not activated.

  • If activateRule is true, the Entity Modification Rule is activated.

The Activation Script of the Entity Modification Rule checks the value of the Custom Parameter and returns true or false.

Prerequisites

  • A Domain Model exists, containing at least one Domain Entity. In this example, the Domain Model is called Employee Database, and the Domain Entity is called employees. One of the Domain Entity’s attributes is called last_name. Further attributes are possible but not relevant for this example.

  • One Kafka Topic for source and target each exists, referencing the Domain Model and Domain Entity mentioned above.

  • A Custom Parameter called activateRule of type Boolean exists. The default value is set to false.

Steps

Step 1: Create the Entity Modification Method

Create an Entity Modification Method that will later be used in the Entity Modification Rule.

Since modifying the data is not the main focus of this guide, the example keeps the modification logic simple. The Activation Script will control whether this modification is applied.

Under the MASKING tab, create a new Entity Modification Method.

Use the following settings:

  • Name: MaskingLastName

Add the following code to the apply() method:

def apply() {
    // first, get the value of the attribute "last_name"
    def value = data.get("last_name")

    // then append "(copied)" to the value
    value = value + " (copied)"

    // and replace the original value with the modified value
    data.put("last_name", value)

    return true
}

Step 2: Create the Entity Modification Rule

Create an Entity Modification Rule on the Domain Entity employees of the Domain Model Employee Database.

This rule will be activated or deactivated based on the Custom Parameter activateRule.

Navigate to:

  • Domain Model: Employee Database

  • Domain Entity: employees

Create a new Entity Modification Rule with the following settings:

  • Name: MaskLastNameRule

  • Entity Modification Method: MaskingLastName

Add the following code to the Activation Script of the Entity Modification Rule:

/*
 * This function decides whether this entity modification rule should be activated.
 */
def isActive() {
    // Activate the rule based on the Custom Parameter "activateRule"
    // The parameter is expected to be defined on the corresponding task object.
    return task.activateRule == 'true'
}
If the Custom Parameter value is available as a Boolean in your XDM version, use return task.activateRule == true instead.

Step 3: Create the Entity Copy Task Template

Create an Entity Copy Task Template.

Use the following settings:

  • Name: CopyEmployees

  • Source connector type: Kafka Topic

  • Target connector type: Kafka Topic

  • Source kafka topic: the source Kafka Topic from the prerequisites

  • Target kafka topic: the target Kafka Topic from the prerequisites

Add the Custom Parameter activateRule to the Task Template.

Since the default value is false, the Entity Modification Rule is not activated by default when using this Task Template.

Step 4: Create a Task for the Entity Copy Task Template

Create a Task from the Entity Copy Task Template.

Use the following settings:

  • Task name: CopyEmployeesTaskMod

  • Custom Parameter: activateRule = true

By setting activateRule to true, the Entity Modification Rule is activated during execution. The modification defined in the Entity Modification Method is applied.

Step 5: Execute the Task and Verify the Result

Execute the Task CopyEmployeesTaskMod.

Because activateRule is set to true, the Entity Modification Rule is activated.

The value of the attribute last_name is modified by appending "(copied)" to it.

Verify the result by checking the target Kafka Topic after task execution.

Benefits

This approach provides the following benefits:

  • Similar Task Templates do not need to be duplicated.

  • Entity Modification Rules can be activated or deactivated per Task.

  • The same Task Template can support different execution scenarios.

  • Rule activation logic remains transparent and configurable.

Conclusion

This guide showed how to use a Custom Parameter of an Entity Copy Task inside the Activation Script of an Entity Modification Rule.

By using the Activation Script, the Entity Modification Rule can be activated or deactivated based on the value of a Custom Parameter in the Task configuration.

This makes Entity Copy Tasks more flexible and reduces the need for multiple similar Task Templates.