Skip to main content
Version: 8.1

Make the field on a record page required

Level: intermediate
Example

Make the Business phone field on the contact page required. The field must be required for the "Customer" type contacts, i. e., the contacts with "Customer" specified in the Type field.

Create a replacing view model schema of the contact page

  1. Go to the Configuration section and select a custom package to add the schema.

  2. Click AddReplacing view model on the section list toolbar.

  3. Fill out the schema properties.

    • Set Code to "ContactPageV2."
    • Set Title to "Display schema - Contact card."
    • Select "ContactPageV2" in the Parent object property.
  4. Add the BusinessRuleModule and ConfigurationConstants modules as dependencies to the declaration of the view model class.

  5. Make the field required.

    To do this, set the rules property for the Phone column:

    1. Set the ruleType property to BINDPARAMETER. The value sets the business rule type. The BusinessRuleModule.enums.RuleType enumeration represents the rule types.
    2. Set the property property to REQUIRED. The value marks the column as required. The BusinessRuleModule.enums.Property enumeration represents the properties of the BINDPARAMETER business rule.
    3. Specify the execution conditions of the business rule in the conditions array. The Type column value must match the ConfigurationConstants.ContactType.Client configuration constant that includes the ID of the "Customer" record of the Contact types lookup.

    View the source code of the replacement view model of the contact page below.

    ContactPageV2
    /* Specify the BusinessRuleModule and ConfigurationConstants modules as dependencies. */
    define("ContactPageV2", ["BusinessRuleModule", "ConfigurationConstants"], function(BusinessRuleModule, ConfigurationConstants) {
    return {
    /* The name of the record page object's schema. */
    entitySchemaName: "Contact",
    /* The business rules of the record page's view model. */
    rules: {
    /* The set of rules for the [Phone] column of the view model. */
    "Phone": {
    /* The requirement of the [Phone] field depends on the [Type] field value. */
    "BindParameterRequiredAccountByType": {
    /* The BINDPARAMETER rule type. */
    "ruleType": BusinessRuleModule.enums.RuleType.BINDPARAMETER,
    /* The rule controls the REQUIRED property. */
    "property": BusinessRuleModule.enums.Property.REQUIRED,
    /* The array of conditions that trigger the rule. Checks whether the [Type] column value is "Customer." */
    "conditions": [{
    /* The left side expression of the condition. */
    "leftExpression": {
    /* The expression type is attribute (column) of the view model. */
    "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
    /* The name of the view model column whose value to compare in the expression. */
    "attribute": "Type"
    },
    /* Set the comparison operation type to equal. */
    "comparisonType": Terrasoft.ComparisonType.EQUAL,
    /* The right side expression of the condition. */
    "rightExpression": {
    /* Set the expression type to constant. */
    "type": BusinessRuleModule.enums.ValueType.CONSTANT,
    /* The value to compare to the left side expression. */
    "value": ConfigurationConstants.ContactType.Client
    }
    }]
    }
    }
    }
    };
    });
  6. Click Save on the Designer's toolbar.

Outcome of the example

To view the outcome of the example:

  1. Refresh the Contacts section page.
  2. Select "Customer" in the Type field of the contact page if needed.

As a result, Creatio will make the Business phone field required for the "Customer" type contacts.

If you try to save a "Customer" type contact whose Business phone field is empty, a message box will open.

The Business phone field is optional for other contact types. For example, "Employee."


Resources

Package with example implementation