Dynamic context in widgets

You can use dynamic context in custom widgets: properties whose number and types are not known when the widget is created and published. These properties are generated by a script that sends a request to the server or an external system.

When a system administrator places a widget with dynamic context on a form or page and opens its settings, the script runs. Data from the external system is saved in a widget property and displayed in the widget settings for further use.

How a widget with dynamic context works

The following features are used to work with dynamic context in a widget:

  • A system property of the Arbitrary type: it allows you to save dynamic properties obtained by the script in .json format.
  • A system Dynamic binding widget: it is placed in the custom widget settings window. It allows you to display the contents of a property of the Arbitrary type as input and output values and map them to the context of the page or form where the custom widget is placed.

Use case for a widget with dynamic context

Let's see how a custom Calculator widget works. It is designed to perform a specific accounting operation. The available operations and their parameters are stored on the server, and the administrator selects one in the widget settings. The administrator works with this widget in two steps:

  1. Creating a widget with dynamic context.

The scripts are configured to retrieve dynamic context data from the server when the widget is placed in another interface, such as a page. 

  1. Configuring the widget for users.

The following actions are performed with dynamic context:

  1. The system administrator places the widget on the page where the user will perform calculations. The script for initializing the widget settings form then runs. The list of accounting operations is loaded from the server and saved in a variable of the Category type.
  2. In the widget settings window, the administrator selects the operation to be performed by the widget. The script then runs again. The input and output parameters of the selected operation are loaded from the server. The retrieved data is saved in a variable of the Arbitrary type.
  3. On the widget settings form, the operation parameters are displayed in the Dynamic binding widget. The administrator maps them to the page context to retrieve the input data entered by the user and display the operation result on the page.

For more information about these configuration steps, see Create a widget with dynamic context.