Creatio development guide
PDF
This documentation is valid for Creatio version 7.11.0. We recommend using the newest version of Creatio documentation.

How to make the field required by a specific condition

Glossary Item Box

Case description

Set fields on the contact edit page so that the [Account] field is required only when the field [Contact Type] = Customer.

Case implementation algorithm

1. Create a replacement client module of the contact edit page

A replacement client module must be created and [Display schema – Contact card] (Fig. 1) must be specified as the parent object.

The process of creating the replacement page is described in the article Creating a custom client module schema

Fig. 1. — Properties of the replacement edit page

2. Add a rule to the rules property of the page view model

Add a rule with the BINDPARAMETER type for the [Account] column.

3. Set the property property of the rule for the [Account] column

Initialize the property property using the BusinessRuleModule.enums.Property.REQUIRED value.

4. Add a condition for the rule implementation to the conditions array

The rule is implemented if the [Type] column value of the view model is equal to the value of the [Customer] contact type identifier.

// Add BusinessRuleModule and ConfigurationConstants to the list of module dependencies.
define("ContactPageV2", ["BusinessRuleModule", "ConfigurationConstants"],
    function (BusinessRuleModule, ConfigurationConstants) {
        return {
            // Object schema name of the edit page.
            entitySchemaName: "Contact",
            details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
            diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
            // Rule object for the edit page view model.
            rules: {
                // Rule set for the [Account] column of the view model.
                "Account": {
                    // Rule that determines whether the [Account] field is required
                    // depending on the value in the [Type] field.
                    BindParameterRequiredAccountByType: {
                        // BINDPARAMETER rule type.
                        ruleType: BusinessRuleModule.enums.RuleType.BINDPARAMETER,
                        // The rule regulates the REQUIRED property of the field. 
                        property: BusinessRuleModule.enums.Property.REQUIRED,
                        // Array of conditions required for the rule to trigger. 
                        // In this case the array contains single condition that
                        // determines whether the value in the [Type] column is “Customer”. 
                        conditions: [{
                            // Expression of the left part of the condition.
                            leftExpression: {
                                // The ATTRIBUTE expression type points to the fact that
                                // a view model attribute (column) is used as expression. 
                                type: BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                                // Name of the view model column, whose value is compared in the expression.
                                // In this case a lookup column is specified, therefore
                                // the attributePath property must be additionally specified.
                                attribute: "Type",
                                // Name of the lookup column specified in the attribute property.
                                attributePath: "Id" 
                            },
                            // Type of the comparison operation. 
                            comparisonType: Terrasoft.ComparisonType.EQUAL,
                            // Expression of the right part of the condition.
                            rightExpression: {
                                // The CONSTANT expression type points to the fact that
                                // a constant expression is used.
                                type: BusinessRuleModule.enums.ValueType.CONSTANT,
                                // The value whith which the expression in the left part
                                // is compared. In this case the expression is the ContactType
                                // enumeration from the ConfigurationConstants module.
                                value: ConfigurationConstants.ContactType.Client
                            }
                        }]
                    }
                }
            }
        };
    });

5. Save the created replacement page schema

When the schema is saved and the web-page of the system is updated on the contact edit page, the [Account] field is required if the contact type is Customer (Fig. 2, 3, 4).

Fig. 2. — Demonstrating the case implementation result (the type is not filled; the [Account] field is optional)

Fig. 3. — Demonstrating the case implementation result (the type is Customer; the [Account] field is mandatory)

 

Fig. 4. — Demonstrating the case implementation result (the type is Contact person; the [Account] field is optional)

 

 

 

 

© bpm'online 2002-2018.

Did you find this information useful?

How can we improve it?