# $mandatoryIf() - Mandatory fields

This keyword is employed to enforce that a field must contain a value when saving a record under specific conditions. The most common use case for the $mandatoryIf keyword arises when you require a field to be mandatory depending on the value of another field.

# Install:

cob-cli customize madantoryIf

WARNING

Requires RecordM restart

# Usage:

$mandatoryIf(<field name> [=,!=,>,>=,<,<=] [value])

Rules:

  1. You can make a field mandatory with $mandatoryIf(field=) or $mandatoryIf(field!=) when the related field value is empty or not empty respectively.
  2. It can handle alphanumeric comparisons also.

The field built with this keyword will be highlighted with a red border when the condition is true and the field has no value.

WARNING

Notice that the field will only be validated when saving any changes made to the instance.

# Examples:

# 1. Making mandatory the field Year of Join Eu if it is a member

$mandatoryIf(Member Of EU = Yes)


# 2. Making mandatory the field Population size whenever a country is selected or not empty

$mandatoryIf(Country!=)


# 3. Making mandatory the field Description when the number of affected files is greater than 5.

$mandatoryIf(Number of affected Files > 5)