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

Adding the [FILTRATION] rule to the edit page

Glossary Item Box

Introduction

Use the FILTRATION rule to set up the filtering of values in view model columns. For example, you can filter a lookup column depending on the current status of a page. For more information on business rules, see the “Setting the edit page fields using 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.

NOTE

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.

Case implementation algorithm

1. Create a replacing contact page

Create a replacing client module and specify the ContactPageV2 (contact page view schema) as parent (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. Below is the resulting source code of the 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 source code of the replacing view model schema of the contact edit page is as follows:

// Add the BusinessRuleModule module to the list of module dependencies.
define("ContactPageV2", ["BusinessRuleModule", "ConfigurationConstants"],
    function(BusinessRuleModule, ConfigurationConstants) {
        return {
            // Edit page object schema name.
            entitySchemaName: "Contact",
            // The property that contains a collection of business rules of the page view model schema.
            rules: {
                // A set of rules for the [City] view model column.
                "City": {
                    // Rule for filtering the [City] column by the value of the [Region] column.
                    "FiltrationCityByRegion": {
                        // Rule type: FILTRATION. 
                        "ruleType": BusinessRuleModule.enums.RuleType.FILTRATION,
                        // Reverse filtering is enabled.
                        "autocomplete": true,
                        // The value will be cleared if the [Region] column value is modified.
                        "autoClean": true,
                        // Path to the filtering column in the [City] lookup schema,
                        // which is referenced by the [City] view model column
                        // of the edit page.
                        "baseAttributePatch": "Region",
                        // Type of comparison operation in the filter.
                        "comparisonType": Terrasoft.ComparisonType.EQUAL,
                        // The view model column (attribute) is used as the
                        // value during comparison.
                        "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                        // Name of the edit page view model column,
                        // whose value will be used for filtering.
                        "attribute": "Region"
                    }
                },
                // Rule set for the [Region] view model column.
                "Region": {
                    "FiltrationRegionByCountry": {
                        "ruleType": BusinessRuleModule.enums.RuleType.FILTRATION,
                        "autocomplete": true,
                        "autoClean": true,
                        "baseAttributePatch": "Country",
                        "comparisonType": Terrasoft.ComparisonType.EQUAL,
                        "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                        "attribute": "Country"
                    }
                }
            },
            // The settings for the visualization of the [City] and [State/Province] 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. 3).

Fig. 2. New fields in the contact profile

Fig. 3. Filtering

Fig. 4. Filtered values in the lookup selection window

© bpm'online 2002-2018.

Did you find this information useful?

How can we improve it?