Hide a feature at the development stage on a page

Medium
PDF

Example. Hide a custom Feature button on a record page of a custom Feature Service section. The button contains the feature at the development stage.

1. Set up the page UI 

  1. Add the developed feature to hide.

    1. Open the Feature page and fill out the feature properties:

      • Set Feature code to "UsrShowMyButton."
      • Set Feature name to "Show My Button."
    2. Click Create feature.
  2. Create a custom Feature Service app based on the Records & business processes template. To do this, follow the guide in the user documentation: Create a custom app.
  3. Open the Feature service form page page in the working area of the Feature Service app page.
  4. Delete the Name field the Feature Service form page page includes by default.
  5. Add a button that contains the feature at the development stage.

    1. Add a Button type component to the toolbar of the Freedom UI Designer.
    2. Click in the action panel of the Freedom UI Designer and fill out the button properties in the setup area.

      • Set Title to "Feature."
      • Select "Primary" in the Style property.
  6. 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. Hide the feature at the development stage 

Configure the business logic in the Client Module Designer. For this example, hide the feature at the development stage.

  1. Enable the sdk.FeatureService service that checks the feature status. To do this, add @creatio/sdk to the AMD module as a dependency.

    AMD module dependencies
    /* Declare the AMD module. */
    define("UsrAppFeatureService_FormPage", /**SCHEMA_DEPS*/["@creatio/sdk"] /**SCHEMA_DEPS*/, function/**SCHEMA_ARGS*/(sdk)/**SCHEMA_ARGS*/ {
            ...
        };
    });
    
  2. Add the ShowMyButton attribute that stores feature status data to the viewModelConfig schema section.

    viewModelConfig schema section
    viewModelConfig: /**SCHEMA_VIEW_MODEL_CONFIG*/{
        "attributes": {
            ...,
            /* The attribute that stores the feature status. */
            "ShowMyButton": {}
        }
    }/**SCHEMA_VIEW_MODEL_CONFIG*/,
    
  3. Bind the visible property of the FeatureButton element to the ShowMyButton model attribute in the viewConfigDiff schema section.

    viewConfigDiff schema section
    viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
        {
            "operation": "insert",
            "name": "FeatureButton",
            "values": {
                ...,
                /* The property that flags the field as visible. Bound to the ShowMyButton attribute. */
                "visible": "$ShowMyButton"
            },
            ...
        }
    ]/**SCHEMA_VIEW_CONFIG_DIFF*/,
    
  4. Add a custom implementation of the crt.HandlerViewModelInitRequest system query handler to the handlers schema section. Execute the handler when Creatio initializes the View model.

    1. Create an instance of the service that checks the feature status from @creatio/sdk.
    2. Retrieve the status of the feature that has the UsrShowMyButton code and specify the status in the ShowMyButton attribute.
    handlers schema section
    handlers: /**SCHEMA_HANDLERS*/[
        {
            request: "crt.HandleViewModelInitRequest",
            /* The custom implementation of the system query handler. */
            handler: async (request, next) => {
                /* Create an instance of the service that checks the feature status from @creatio/sdk. */
                const featureService = new sdk.FeatureService();
                /* Retrieve the UsrShowMyButton feature status and specify it in the ShowMyButton attribute. */
                request.$context.ShowMyButton = await featureService.getFeatureState('UsrShowMyButton');
                /* Call the next handler if it exists and return its result. */
                return next?.handle(request);
            }
        }
    ] /**SCHEMA_HANDLERS*/,
    
    Complete source code of the page schema
  5. Click Save on the Client Module Designer's toolbar.

Outcome of the example 

To view the outcome of the example for the feature at the development stage:

  1. Open the Feature Service app page and click Run app.
  2. Click New on the Feature Service app toolbar.

As a result, Creatio will hide the Feature button that contains the feature at the development stage on the Feature Service app page.

To view the outcome of the example for the fully developed feature:

  1. Enable the feature that has UsrShowMyButton code.

    1. Open the Feature page.
    2. Enable the Show My Button feature in the page list.
    3. Click Save changes and refresh the page.
  2. Refresh the Feature Service app page.
  3. Click New on the Feature Service app toolbar.

As a result, Creatio will display the Feature button that contains the fully developed feature on the Feature Service app page.