Set up the display condition of a field on a page

Medium
PDF

Example. Set up the display condition for the Sick leave, days left field on the record page of the custom Requests section. Display the field for requests that originate from employees, i. e., requests whose Originator type field is set to "Employee."

1. Set up the page UI 

  1. Create a custom Requests app based on the Records & business processes template. To do this, follow the guide in the user documentation: Create a custom app.
  2. Open the Requests form page page in the working area of the Requests app page.

    The Requests form page page includes the Name field by default.

  3. Add a field that contains the request originator type.

    1. Add a Dropdown type field to the working area of the Freedom UI Designer.
    2. Click in the action panel of the Freedom UI Designer and fill out the field properties in the setup area.

      • Set Title to "Originator type."
      • Set Code to "UsrOriginatorType."
      • Select "Contact type" in the Lookup property.
  4. Add a field that contains the number of sick days left.

    1. Add a Number type field to the working area of the Freedom UI Designer.
    2. Click in the action panel of the Freedom UI Designer and fill out the field properties in the setup area.

      • Set Title to "Sick leave, days left."
      • Set Code to "UsrSickDaysLeft."
  5. Click in the action panel of the Freedom UI Designer. After you save the page settings, Creatio opens the source code of the Freedom UI page.

2. Set up the field display condition 

Configure the business logic in the Client Module Designer. For this example, set up the field display condition.

  1. Add an IsRequestFromEmployee attribute that stores data about the contact type from which the request originates to the viewModelConfig schema section.

    viewModelConfig schema section
    viewModelConfig: /**SCHEMA_VIEW_MODEL_CONFIG*/{
        "attributes": {
            ...,
            /* The attribute that stores the request originator type. */
            "IsRequestFromEmployee": {}
        }
    }/**SCHEMA_VIEW_MODEL_CONFIG*/,
    
  2. Bind the visible property of the UsrSickDaysLeft element to the IsRequestFromEmployee model attribute in the viewConfigDiff schema section. If the request originates from an Employee type contact, display the Sick leave, days left field. Hide the field for other contact types.

    viewConfigDiff schema section
    viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
        ...,
        {
            "operation": "insert",
            "name": "UsrSickDaysLeft",
            "values": {
                ...,
                /* The property that flags the field as visible. Bound to the IsRequestFromEmployee attribute. */
                "visible": "$IsRequestFromEmployee"
            },
            ...
        }
    ]/**SCHEMA_VIEW_CONFIG_DIFF*/,
    
  3. Add a custom implementation of the crt.HandleViewModelAttributeChangeRequest system query handler to the handlers schema section. Run the handler when the value of any attribute changes, including changes made after loading the attribute values from the data source. The handler checks the UsrOriginatorType attribute value. If the new attribute value refers to the "Employee" value of the Contact type lookup, set the IsRequestFromEmployee attribute value to true, otherwise set it to false. The unique ID of the Employee type contact set as the employeeOriginatorTypeId constant is stored in the corresponding string of the Contact type lookup record. In this example, the ID of the Employee type contact is "60733efc-f36b-1410-a883-16d83cab0980."

    handlers schema section
    handlers: /**SCHEMA_HANDLERS*/[
        {
            request: "crt.HandleViewModelAttributeChangeRequest",
            /* The custom implementation of the system query handler. */
            handler: async (request, next) => {
                /* Check the request originator type. */
                if (request.attributeName === 'UsrOriginatorType') {
                    const employeeOriginatorTypeId = '60733efc-f36b-1410-a883-16d83cab0980';
                    const selectedOriginatorType = await request.$context.UsrOriginatorType;
                    const selectedOriginatorTypeId = selectedOriginatorType?.value;
                    /* If the request originates from an employee, set the IsRequestFromEmployee to true. */
                    request.$context.IsRequestFromEmployee = selectedOriginatorTypeId === employeeOriginatorTypeId;
                }
                /* Call the next handler (if it exists) and return its result. */
                return next?.handle(request);
            }
        }
    ]/**SCHEMA_HANDLERS*/,
    
    Complete source code of the page schema
  4. Click Save on the Client Module Designer's toolbar.

Outcome of the example 

To view the outcome of the example:

  1. Open the Requests app page and click Run app.
  2. Click New on the Requests app toolbar.
  3. Enter "Sick leave" in the Name field.
  4. Select "Employee" in the Originator type field.

As a result, Creatio will display the Sick leave, days left field on the page of the request that originates from an Employee type contact.

Creatio will not display the Sick leave, days left field for requests that originate from other contact types, e. g., Customer.