Changing detail visibility depending on the field value

Question

In the [Contacts] section, I created a [Driver's documents] detail, the UsrSchema6Detail schema. I need to display it, if the selected job title is [Driver]. If the job title is different or not selected at all, the detail is hidden.

 I added a business rule to the contact schema, but it does not work.

rules: {
   "UsrSchema6Detail": {
      BindParametrVisibilePlaceByType: {
         // Rule type: BINDPARAMETER.
         ruleType: BusinessRuleModule.enums.RuleType.BINDPARAMETER,
         // Rule is regulated by the VISIBLE field value.
         property: BusinessRuleModule.enums.Property.VISIBLE,
         conditions: [{
            // Expression of the left part of the condition.
            leftExpression: {
               //The ATTRIBUTE expression type indicates, that
               // the view model attribute (column)acts as the expression.
               type: BusinessRuleModule.enums.ValueType.ATTRIBUTE,
               // Name of the view model column, whose value was compared in the expression.
               attribute: "Job"
            },
            // Compare operation type.
            comparisonType: Terrasoft.ComparisonType.EQUAL,
            // Expression of the right part of the condition.
            rightExpression: {
               type: BusinessRuleModule.enums.ValueType.CONSTANT,
               value: "703e34d6-4113-43b5-84dc-2e1f8635c6d4"
            }
         }]
      }
   }
}

If I apply this rule to the [Department] column, it works OK.

Answer

Using business rules is not a good solution for your business case.

Below is an example of code for hiding the [Communication options] detail on the edit page of an [Account]. Create the AccountPagev2 replacing module, the following code is added in the diff property:

{
    "operation": "merge",
    "name": "Communications",
    "values": {
        "visible" : {
            "bindTo": "communicationsVisibility"
        }
    }
}

Declare the method responsible for detail visibility in the methods property:

communicationsVisibility: function(){
    var type = this.get("Type");
    return !!type && type.displayValue === "Our company";
}

As a result, the detail will be visible only in case the type is specified as "Our company". You can hide any detail similarly.

Like 0

Like

Share

0 comments
Show all comments