Create Condition Using a Field's Initial Value

When choosing a field in the condition builder, you might see fields listed under both Field Values and under Initial Field Values.

The Initial Field Value is set in the page's metadata. The value might be set by the page developer, but you can also edit the page's metadata in the JSON editor to set a value when extending a page. The initial value set in the metadata isn't affected by changes made by rules or users. If the field is a number and no initial value is set, the value is 0; if the field is a string, the value is an empty string.

The Field Value, on the other hand, is the current value displayed in a page. This value may already have been modified by a rule or user. For example, say the value for the Head Count field is set to 50 in the page's JSON (the Initial Field Value). There might be some rule that sets the field's value (the Field Value) to 60. The Field Value is displayed in the Head Count field in the form. The user may then change the Head Count field to 70 in the form, so the Field Value for Head Count is now 70. The Head Count Initial Field Value, however, is still 50.

Let's look at how to set the Head Count field's initial value in a page, and then add a rule that makes the Head Count field read only when the field's initial value is greater than 100.

  1. Open the page you want to configure in the Designer, and then open the page's JSON editor.
  2. Locate the "metadata" element in the JSON.

    The metadata element for a form might look something like this.

    "metadata": {
        "hCMContactsCreateHcmContactsNamesMetadata": {
          "type": "vb/DynamicLayoutMetadataProviderDescriptor",
          "defaultValue": {
            "endpoint": "site_kenter:HCMContacts/create_hcmContacts-names"
          }   
        }
    },
  3. Add an initial value for the field.

    To add an initial value of 101 for the Head Count field, add something like this (in bold) to the JSON:

    "metadata": {
        "hCMContactsCreateHcmContactsNamesMetadata": {
          "type": "vb/DynamicLayoutMetadataProviderDescriptor",
          "defaultValue": {
            "endpoint": "site_kenter:HCMContacts/create_hcmContacts-names",
            "initialValue": {
               "HeadCount": 101
            }
          }   
        }
    },
  4. In the business rules editor, create a new form rule.
  5. Create a condition where the initial value of Head Count is greater than 100.

    In the criterion dropdown list, be sure to select Head Count under Initial Field Values (as opposed to under Field Values):



  6. Set the Read Only property of the Head Count field to Read Only.

In this example, if the rule is applied in the page, the Head Count field is read only.