Skip to content

ensure

Description

ensure guarantees that at least the specified instance(s) exist(s). If they do, there are no further actions taken. If they don't, the system will create what is missing.

It can only be used when writing creation type process rules.

Example

ensure 2 Person, AccountHolder

If the case already has two persons that are accountholders, this expression will change nothing.

However, if there is only one person who is accountholder, the system will create a second person with the role AccountHolder.

Giving values to the ensured instances

Info

New in Atfinity 18.

An ensure can name the instances it ensures with as, give values to the instances it creates with with, or both.

p is Person, AccountHolder
---
ensure 2 Person, BeneficialOwner as n with
    domicile := p.domicile
    relationship := "spouse"
end
n.risk_level := p.risk_level

The values between with and end are given once, to each instance this ensure creates.

  • An instance that already existed keeps its fields as they are, including the empty ones. The same goes for an existing instance that only receives the role
  • When nothing is created, the expressions are not evaluated
  • An expression that has no value yet when the instance is created gives nothing, and reading a field here does not ask for it. Let the condition of the rule depend on the fields the values need, so the instance is created once they are known
  • The value is stored like one a user entered: a user can change or clear it, it is not given again afterwards, and := leaves it alone
  • The left side is the key of an information of the new instance, without a name in front, and only := is allowed
  • File, structure, SVG and review fields cannot get an initial value

The assignments after the ensure behave like every other assignment of a rule, on every instance the ensure covers, existing and created. They can only assign to the name given with as. That name has to be new in the rule, and it is only known in its own ensure, after the number of instances.

Every instance evaluates its own expressions, in which the name given with as is that instance. The with values are set first, so n.tax_country := n.domicile after the example above reads the domicile just given.

Use with for a starting value a user is free to change, and an assignment for a value the rule keeps filled in.

When the case holds more matching instances than the ensure asks for, an ensure with as or with keeps the instances it created itself, then takes instances a user created, then the others. An ensure without as and with takes instances a user created first. So when a user adds a matching instance to a case where ensure 3 Person has created three, the plain ensure counts the added one and removes one of its own that nobody has changed, leaving three. An ensure with as or with keeps its three and the added one, and its values stay on its own instances. An instance the ensure created while an instance its condition matches was being created in the same step is not recognised as its own afterwards, and is chosen like any other instance.