Best Practices - Propagation Rules

The purpose of this document is to provide best practices for the propagate event, which is called on a property every time it is successfully modified after the control.

Principles

  • A propagate event can be run on properties of the same class.
  • A propagate event can be run on properties of child classes, even in a loop, if several values have to be propagated.
  • A propagate event must not be run between properties of different lines of a collection.

The reason for the latter rule is that it could create propagation loops. This can happen when the order in which data is stored is different from the order in which it is presented, or the order in which it will be set back into the database. Because of this, such algorithms are too unpredictable.

When a propagation rule is run, the order in which the fields are sent from the user interface can also depend on personalizations, as well as the communication mode.

Example

  • A class contains two properties A and B.
  • A propagation rule has been defined on property A. It unconditionally assigns value "AA" to B.
  • A representation contains both fields A and B, and is used in CRUD management.
  • The user enters value "AA" for the A field, and "BB" for the B field.

This is performed by the following code:

# This label is called from $PROPERTIES label in the script associated the class
$PROPAGATE_A
  this.B="AA"
Return

In this example, field A should have value "AA", and field B should have value "BB". However, this code is too unpredictable because field B can end up with value "AA" if:

  • the network bandwidth is not good enough,
  • the user enters the value for field B before the value for field A,
  • the representation is used on a mobile.

Use the following code to avoid this issue:

# This label is called from $PROPERTIES label in the script associated the class
$PROPAGATE_A
  If this.B<>""
    this.B="AA"
  Endif
Return

With this code, the propagation rule is only applied if no value is entered for field B. If, for any reason, you want to reapply the "AA" value to field B even if a value has been entered, the best solution is to implement a SET_B_VALUE method in the class, and to call it from a dedicated link called "Init B" in the representation.