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

The BINDPARAMETER rule. How to make a field required based on a specific condition

Glossary Item Box

Introduction

BINDPARAMETER rule is used for resolving he following tasks:

  • hide and display fields
  • lock and unlock fields
  • make fields required or optional

For more information on business rules, see the “Setting the edit page fields using business rules” article.

In Creatio, you can configure business rules using developer tools as well as the section wizard. For more information please refer to the "Setting up business rules” article.

Case description

Set up the contact edit page fields so that the [Business phone] field is required on condition that the [Contact type] field is populated with the “Customer” value.

Source code

You can download the package with case implementation using the following link.

Case implementation algorithm

1. Create a replacing client module for the contact edit page.

Create a replacing client module and specify the [Display schema — Contact card] schema as parent object (Fig. 1). The procedure for creating a replacing page is covered in the “Creating a custom client module schema” article.

Fig. 1. Replacing edit page properties

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

Add the BINDPARAMETER type rule for the Phone column to the rules property of the page view model. Set the property rule value to BusinessRuleModule.enums.Property.REQUIRED. Add a rule execution condition to the conditions array – the Type column value of the model should be equal to the ConfigurationConstants.ContactType.Client configuration constant.

The ConfigurationConstants.ContactType.Client configuration constant contains the “Client” record identifier of the [Contact type] lookup.

The replacing schema source code is as follows:

// Add the BusinessRuleModule and ConfigurationConstants modules to the module dependency list. 
define("ContactPageV2", ["BusinessRuleModule", "ConfigurationConstants"],
    function(BusinessRuleModule, ConfigurationConstants) {
        return {
            // Name of the edit page object schema.
            entitySchemaName: "Contact",
            // Rules of the edit page view model.
            rules: {
                // Set of rules of the [Business rule] view model column.
                "Phone": {
                    // Dependency of the [Business phone] field "required" property on the [Type] field value. 
                    "BindParameterRequiredAccountByType": {
                        // BINDPARAMETER rule type.
                        "ruleType": BusinessRuleModule.enums.RuleType.BINDPARAMETER,
                        // The rule regulates the REQUIRED property. 
                        "property": BusinessRuleModule.enums.Property.REQUIRED,
                        // Condition array, whose performance triggers the rule execution. 
                        // Defines if the [Type] column value is equal to the "Client" value. 
                        "conditions": [{
                            // Expression of the left side of the condition. 
                            "leftExpression": {
                                // Expression type — view model attribute(column). 
                                "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                                // Name of the view model column whose value is compared in the expression. 
                                "attribute": "Type"
                            },
                            // Comparison operation type.
                            "comparisonType": Terrasoft.ComparisonType.EQUAL,
                            // Expression of the right side of the condition.
                            "rightExpression": {
                                // Expression type – constant value.
                                "type": BusinessRuleModule.enums.ValueType.CONSTANT,
                                // The comparison value for the left side of the expression. 
                                "value": ConfigurationConstants.ContactType.Client
                            }
                        }]
                    }
                }
            }
        };
    });

After you save the schema and update the application web page, the [Business phone] filed of the contact edit page will be required on condition the contact type is the “Customer”.

Fig. 2. Case result The [Business phone] field – optional

Fig. 3. Case result The [Business phone] field – required

See also

© Creatio 2002-2020.

Did you find this information useful?

How can we improve it?