The BINDPARAMETER rule. How to hide a field on an edit page 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.
NOTE In bpm’online, you can configure business rules using developer tools as well as the section wizard. For more information please refer to the “Setting up the business rules”. |
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. |
Source code
Use this link to download the case implementation package.
Case implementation algorithm
1. Create a replacing object and add a new column to it.
Create an [Activity] replacing object and add a new [Meeting place] column of the “string” type to it (Fig. 1). Learn more about creating a replacing object schema in the “Creating the entity schema” article.
Fig. 1. Adding a custom column to the replacing object
2. Create a replacing client module for the activity page
Create a replacing client module and specify the [Activity edit page] schema as parent object (Fig. 2). The procedure for creating a replacing page is covered in the “Creating a custom client module schema” article.
Fig. 2. Replacing edit page properties
3. Add a new field to the activity edit page.
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 localizable string (Fig. 3) and bind it to the field title.
Fig. 3. Localizable string properties
4. Add a rule to the “rules” property of the page view model
For the UsrMeetingPlace column, add the rule with the BINDPARAMETER type to rules property of the page view model. Set the BusinessRuleModule.enums.Property.VISIBLE value for the rule’s property. Add the following condition for rule execution to the conditions array: the value in the ActivityCategory column of the model should be equal to the ConfigurationConstants.Activity.ActivityCategory.Meeting configuration constant.
NOTE The ConfigurationConstants.Activity.ActivityCategory.Meeting configurational constant contain the id of the “Meeting” record of the [Activity category] lookup. |
The replacing schema source code is as follows:
// Add the module BusinessRuleModule and ConfigurationConstants to the dependency list of the module. define("ActivityPageV2", ["BusinessRuleModule", "ConfigurationConstants"], function(BusinessRuleModule, ConfigurationConstants) { return { // Name of the page schema of the edit page. entitySchemaName: "Activity", // Displaying a new field on the edit page. diff: /**SCHEMA_DIFF*/[ // Metadata for adding a field [Meeting place]. { // The operation of adding a component to a page. "operation": "insert", // The meta name of the parent container to which the field is added. "parentName": "Header", // The field is added to the parent // component's collection. "propertyName": "items", // The name of the column of the schema to which the component is bound. "name": "UsrMeetingPlace", "values": { // Field title. "caption": {"bindTo": "Resources.Strings.MeetingPlaceCaption"}, // Location of the field. "layout": { "column": 0, "row": 5, "colSpan": 12 } } } ]/**SCHEMA_DIFF*/, // Rules of the edit page view model Правила модели представления страницы редактирования. rules: { // A set of rules for the [Meeting place] column of the view model. "UsrMeetingPlace": { // The dependence of visibility of the [Meeting Place] field from the value in [Category] field. "BindParametrVisibilePlaceByType": { // The type of the BINDPARAMETER rule. "ruleType": BusinessRuleModule.enums.RuleType.BINDPARAMETER, // Rule regulates the VISIBLE property. "property": BusinessRuleModule.enums.Property.VISIBLE, // An array of conditions in which the rule is triggered. // Determines whether the value in the [Category] column is equal to the value "Meeting". "conditions": [{ // Expression of the left side of the condition. "leftExpression": { //The type of the expression is the attribute (column) of the view model. "type": BusinessRuleModule.enums.ValueType.ATTRIBUTE, // Name of the view model column which value is compared in the expression. "attribute": "ActivityCategory" }, // The type of comparison operation. "comparisonType": Terrasoft.ComparisonType.EQUAL, // Expression of the right side of the condition. "rightExpression": { // Type of expression is a constant value. "type": BusinessRuleModule.enums.ValueType.CONSTANT, // The value with which the left side expression is compared. "value": ConfigurationConstants.Activity.ActivityCategory.Meeting } }] } } } }; });
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, 5).
Fig. 4. Case result. Activity type is “To do”, the [Meeting place] field is not visible
Fig. 5. Case result. Activity type is “To do”, the [Meeting place] field is visible
See also
- Setting the edit page fields using business rules
- The BINDPARAMETER rule. How to lock a field on an edit page based on a specific condition
- The BINDPARAMETER rule. How to make a field required based on a specific condition
- The FILTRATION rule use case
- Business rules created via wizards