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

The FILTRATION rule use case

Glossary Item Box

Introduction

The FILTRATION rule is used to configure filtering of the lookup column of the view model based on the value of another column. 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 the as well as the section wizard. For more information please refer to the “Setting up the business rules“ article.

Case description

Add the [Country], [State/Province] and [City] fields to the page. If the [Country] field is populated, the values in the [State/Province] field must include only states and provinces of that country. If the [State/Province] field is populated, the values in the [City] field must include only cities located in that state or province. If the [City] field is populated first, the [Country] and [State/Province] fields must be automatically populated with the corresponding values.

The base contact page schema already has a rule for filtering cities by country. Therefore, if the [Country] field is not added, only cities from the country specified for a contact can be selected.

Source code

Use this link to download the case implementation package.

Case implementation algorithm

1. Create a replacing contact 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. Order edit page replacing schema properties

2. Add the [Country], [State/Province] and [City] fields to the page.

To do this, add three configuration objects with the settings for the corresponding field properties to the diff array.

3. Add FILTRATION-type rules to the [City] and [State/Province] columns.

To do this, add two rules of the BusinessRuleModule.enums.RuleType.FILTRATION type to the rules property for the [City] and [Region] columns. To enable reverse filtering (i.e., to automatically populate the [Country] and [State/Province] fields based on the selected city), set the autocomplete property to true.

The replacing schema source code is as follows:

// Add the module BusinessRuleModul to the dependency list of the module.
define("ContactPageV2", ["BusinessRuleModule"],
    function(BusinessRuleModule) {
        return {
            // Name of the schema of the edit page object.
            entitySchemaName: "Contact",
            // A property that contains a collection of business rules for the schema of the page view model.
            rules: {
                // A set of rules for the [City] column of the view model..
                "City": {
                    // The rule for filtering the [City] column by the value of the [Region] column.
                    "FiltrationCityByRegion": {
                        //  FILTRATION rule type. 
                        "ruleType": BusinessRuleModule.enums.RuleType.FILTRATION,
                        // Reverse filtering will be performed.
                        "autocomplete": true,
                        // The value will be cleared when the value of the [Region] column changes.
                        "autoClean": true,
                        // The path to the column for filtering in the [City] reference schema, 
                        // which is referenced by the [City] column of the 
                        // edit page view model.
                        "baseAttributePatch": "Region",
                        // The type of the comparison operation in the filter.
                        "comparisonType": Terrasoft.ComparisonType.EQUAL,
                        // The column (attribute) of the view model will be the comparison value.
                        "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                        // The column name of the view model of the edit page, 
                        // the value of which will be filtered.
                        "attribute": "Region"
                    }
                },
                // A set of rules for the [Region] column of the view model.
                "Region": {
                    "FiltrationRegionByCountry": {
                        "ruleType": BusinessRuleModule.enums.RuleType.FILTRATION,
                        "autocomplete": true,
                        "autoClean": true,
                        "baseAttributePatch": "Country",
                        "comparisonType": Terrasoft.ComparisonType.EQUAL,
                        "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                        "attribute": "Country"
                    }
                }
            },
            // Setting up the visualization of the [Country], [State/Province] and [City] fields on the edit page.
            diff: [
                // Metadata for adding the [Country] field.
                {
                    "operation": "insert",
                    "parentName": "ProfileContainer",
                    "propertyName": "items",
                    "name": "Country",
                    "values": {
                        "contentType": Terrasoft.ContentType.LOOKUP,
                        "layout": {
                            "column": 0,
                            "row": 6,
                            "colSpan": 24
                        }
                    }
                },
                // Metadata for adding the [State/Province] field.
                {
                    "operation": "insert",
                    "parentName": "ProfileContainer",
                    "propertyName": "items",
                    "name": "Region",
                    "values": {
                        "contentType": Terrasoft.ContentType.LOOKUP,
                        "layout": {
                            "column": 0,
                            "row": 7,
                            "colSpan": 24
                        }
                    }
                },
                // Metadata for adding the [City] field.
                {
                    "operation": "insert",
                    "parentName": "ProfileContainer",
                    "propertyName": "items",
                    "name": "City",
                    "values": {
                        "contentType": Terrasoft.ContentType.LOOKUP,
                        "layout": {
                            "column": 0,
                            "row": 8,
                            "colSpan": 24
                        }
                    }
                }
            ]
        };
    });

4. Save the created replacing page schema

After saving the schema and updating the application page, three new fields will be added to the contact profile (Fig. 2). Their values will be filtered based on the values entered in any of these fields. The filtering also works in the lookup selection window (Fig. 4).

Fig. 2. New fields in the contact profile

Fig. 3. Filtering

Fig. 4. Filtered values in the lookup selection window

See also

 

© Creatio 2002-2020.

Did you find this information useful?

How can we improve it?