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 hide the edit page field by a specific condition

Glossary Item Box

Case description

Add a new [Meeting place] field to the activity page. The field will be available only for activities of the [Meeting] type.

NOTE

You can add fields to the edit page manually or via the section wizard.

For more on adding fields to edit pages see the “Adding a new field to the edit page” article.

Case implementation algorithm

1. Create an [Activity] replacing object and add a new [Meeting place] column to it.

To do this, go to the [Configuration] section of the system designer, select a custom package and on the [Schemas] tab, execute the menu command [Add] -> [Replacing object] (Fig.1).

Fig. 1. Creating a replacing object schema

Populate the object properties, specifying [Activity] as the parent object (Fig. 2).

Fig. 2. Properties of the [Activity] replacing object

Add a new [Meeting place] text column to the replacing object (Fig. 3).

Fig. 3. Adding a custom column to the replacing object

Save and publish the object.

2. Create a replacing client module for the activity page

Create a replacing client module and specify the ActivityPageV2 schema as parent (Fig. 4). The procedure for creating a replacing page is covered in the “Creating a custom client module schema” article.

Fig. 4. Order edit page replacing schema properties

3. Add the [Meeting place] field to the activity edit page.

To do this, add a configuration object with the [Meeting place] field properties on the page to the diff array. The process of adding fields to pages is covered in the “Adding a new field to the edit page” article.

To enable localization of this field, add a localized string (Fig. 5) and bind it to the field title.

Fig. 5. Localized string properties

4. Add a rule of the BINDPARAMETER type to the [UsrMeetingPlace] column

In the rules property of the page view model, add a BindParametrVisibilePlaceByType rule of the BusinessRuleModule.enums.RuleType.BINDPARAMETER type for the [UsrMeetingPlace] column. Initialize the rule’s property with the BusinessRuleModule.enums.Property.VISIBLE value. Add the following condition for rule execution to the conditions array: the value in the [ActivityCategory] column must be equal to the Id of the [Meeting] activity category (from the [Activity categories] lookup).

To determine the Id of the [Meeting] category, use an EntitySchemaQuery to the corresponding lookup. Due to the asynchronous nature of this class methods, add a MeetingId attribute to save the query results and run the query during schema initialization. Override the Init() method of the activity page’s base schema.

NOTE

The meeting category Id also

Below is the code of the replacing page:

// Add BusinessRuleModule to the list of module dependencies.
define("ActivityPageV2", ["BusinessRuleModule"],
    function(BusinessRuleModule) {
        return {
            // Name of the edit page object schema.
            entitySchemaName: "Activity",
            // Attribute for saving the needed activity category Id.
            attributes: {
                "MeetingId": {
                    "dataValueType": Terrasoft.DataValueType.TEXT,
                    "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                    "value": ""
                }
            },
            methods: {
                // Schema initialization method.
                init: function() {
                    this.callParent(arguments);
                    this.initMeetingId();
                },
                // Method for determining activity category Id.
                initMeetingId: function() {
                    var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "ActivityCategory"});
                    // Saving module context to a variable.
                    var scope = this;
                    esq.addColumn("Name", "Name");
                    // Executing query.
                    esq.getEntityCollection(function(result) {
                        if (result.success) {
                            // Browsing the values of the [Activity category] lookup.
                            result.collection.each(function(item) {
                                // If the value in the [Name] column is [Meeting].
                                if (item.get("Name") === "Meeting") {
                                    // Obtaining the [Meeting] category Id.
                                    var Id = item.get("Id");
                                    // Setting the attribute value.
                                    scope.set("MeetingId", Id);
                                }
                            });
                        }
                    }, this);
                }
            },
            // Setting visualization of an additional field on the page.
            diff: /**SCHEMA_DIFF*/[
                {
                    // Metadata for adding the [Meeting place] field.
                    "operation": "insert",
                    "parentName": "Header",
                    "propertyName": "items",
                    "name": "UsrMeetingPlace",
                    "values": {
                        "caption": {"bindTo": "Resources.Strings.MeetingPlaceCaption"},
                        "layout": { "column": 0, "row": 6, "colSpan": 12 }
                    }
                }
            ]/**SCHEMA_DIFF*/,
            // Object of the view model rules of an edit page.
            rules: {
                // Rule set for the [UsrMeetingPlace] view model column. 
                "UsrMeetingPlace": {
                    // Setting up display rule for the [UsrMeetingPlace] field based on the value in the [ActivityCategory] column.
                    "BindParametrVisibilePlaceByType": {
                        // Rule type: BINDPARAMETER.
                        "ruleType": BusinessRuleModule.enums.RuleType.BINDPARAMETER,
                        // The rule controls the VISIBLE property of the field.
                        "property": BusinessRuleModule.enums.Property.VISIBLE,
                        // Array of conditions that will trigger the rule.
                        // In this case, the array contains one condition for comparing the value in the [ActivityCategory] column
                        // with the [Meeting] activity category Id.
                        "conditions": [{
                            // Left part expression of the condition.
                            "leftExpression": {
                                // The ATTRIBUTE type of the expression indicates that
                                // a view model attribute (column) is the expression.
                                "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                                // Name of the view model column whose value is being compared in the expression.
                                "attribute": "ActivityCategory"
                            },
                            // Type of comparison operation.
                            "comparisonType": Terrasoft.ComparisonType.EQUAL,
                            // Expression of the condition's right part.
                            "rightExpression": {
                                "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE,
                                // The value with which the left expression is compared. In this case, this is an Id
                                //of an activity type specified via the MeetingId attribute.
                                "attribute": "MeetingId"
                            }
                        }]
                    }
                }
            }
        };
    });

After saving the schema and refreshing the application page, an additional [Meeting place] field will appear on the activity page if the activity category is “Meeting” (Fig. 5, 6).

Fig. 5. Case result: Activity type is “To do”, the [Meeting place] field is not visible

Fig. 6. Case result: Activity type is “Meeting”, the [Meeting place] field is visible

© bpm'online 2002-2018.

Did you find this information useful?

How can we improve it?