Custom modules support common scripts, which let you create libraries of custom functions and types in TypeScript. A common script can be called from server-side scripts in any process, widget, or module.
Using common scripts eliminates duplicate logic and makes code easier to maintain. Calling a common script does not create a separate queue request or add extra load to the system. For example, you can move frequently used operations, such as file conversion or log saving, into a common script.
начало внимание
Common scripts in custom modules are currently being tested and stabilized. This feature is available when the feature flag is enabled. Contact your BRIX sales rep to enable it.
конец внимание
If you import a custom module that contains common scripts into another company running system version 2026.10 or later, you can use the scripts without enabling the feature flag. However, the feature flag must be enabled to edit existing common scripts or create new ones.
This article describes how to create common scripts with custom functions and types and how to use them in other system components by configuring optional dependencies.
начало примечание
Useful articles:
- BRIX TS SDK documentation. Scripting guidelines for BRIX, available system objects, and methods.
- Example of a common script with server-side dependencies. How to configure a common script that uses npm packages with ready-to-use code: file conversion example.
конец примечание
Steps to configure and call a common script
Working with a common script involves several steps. Each step includes links to sections with detailed instructions:
- Create a common script in a module.
- Configure custom types and access to external objects (optional).
If the common script functions need to access external resources or use custom data structures, you can:
- Configure custom types to define your own data structures. You can use them as parameters in common script functions and refer to them in other components to create objects of that type.
- Configure access to other components using optional dependencies to allow the common script code to access other common scripts or objects in various company modules and workspaces.
- Add server-side dependencies for npm packages. In BRIX On-Premises, you can add an archive containing ready-to-use third-party code and use it in your functions.
Describe the core logic that you can reuse in other components:
- Add functions by specifying their names, input parameters, and output parameters.
- Write the function script in TypeScript. You can refer to configured dependencies and custom types in the code.
To use the functions or types defined in a common script in another component:
- Grant the component access to the common script by adding an optional dependency on the module that contains it.
- Import the common script in the component's code and call its functions or use its types.
Step 1. Create a common script
You can create any number of common scripts in a module. Each script groups functions and types for a specific use case.
To add a common script:
- Go to Administration > Modules.
- Hover over the module and click the gear icon that appears.
- Go to the Common Scripts tab and click + Common Script.
- Enter a name and code for the common script. These will be displayed when you configure calls to it from other components. You can also add a description of its purpose.
- Click Save.

The common script settings page opens. You can change its name and description on the Settings tab.
Step 2. Configure access to external objects and custom types (optional)
If the common script needs to use custom data structures, access other common scripts or system components, or use ready-to-use code from external sources, complete the setup before writing the function logic.
Configure custom types for a common script
If the standard data types are not sufficient for your common script, use the Types tab to define your own TypeScript structures, called custom types. For example, you can use them to pass file contents as binary data or create log records with specific fields.
Custom types are defined as TypeScript interfaces using the interface keyword. When defining them, you can:
- Define the structure of an object’s fields.
- Extend standard TypeScript types using the extends keyword.
Note that custom type definitions cannot use the standard any or unknown types or declare enumerations using enum.

You can use custom types in two ways:
- In common script functions, specify a custom type for input and output parameters to define the format of the data the functions accept and return.
- When using the common script in other system components, for example, create an object of a custom type in the component's script based on context data, then process it by calling common script functions.
Important: If you refer directly to a custom type in another component’s code, that code will stop working if the module containing the common script is disabled.
Configure access to other components using optional dependencies
You can allow a common script to access objects from specific system modules or workspaces, including other common scripts.
To do this, configure an optional dependency on the required component in the common script. This lets the code work with external objects without a hard dependency: you can transfer the module containing the common script to other companies, even if those companies do not have the related components.
To configure an optional dependency:
- In the common script settings, go to the Settings.
- In the Optional dependencies field, click + Add Workspace, select a workspace or module from the drop-down list, and click Add.
- In the optional dependencies list, assign an alias to the workspace or module. This descriptive name is used to refer to it in the common script.
- If you added a dependency on a module, you can also configure access to its common scripts. To call a common script from another common script, follow the same procedure as for other components, described in the section on configuring a common script call.

Configure the use of ready-to-use code from npm packages
In BRIX On-Premises, you can use code from third-party libraries in common scripts by adding server-side dependencies for npm packages.
To do this, prepare an archive containing the dependencies and add it to the Files tab, then configure dependency imports on the Scripts tab. For details, see Server dependencies in npm packages.

Step 3. Create common script functions
Functions are the core of a common script. They contain code for recurring operations that you can call from other system components. To configure a function, first add it on the Functions tab, then write its code on the Scripts tab.
Add a function
When creating a function, specify its name and parameters. These define the data it accepts for processing and the result it returns.
To do this:
- On the Functions tab, click + Add.
- In the window that opens, go to the Main tab and fill in the fields:

- Name*. Enter the name to be displayed in code tooltips when users use the function.
- Executable script*. Enter the function name used in scripts. You cannot change it after creation.
- Description. Describe the function’s purpose and usage. The description appears in code tooltips.
- On the Input Parameters and Output Parameters tabs, specify the function parameters that define what data it receives and what it returns.
- To create a parameter, click + Add and fill in the fields:

- Display name*. The parameter name.
- Parameter name*. The name used to refer to the parameter in scripts.
- Tooltip. A description that appears when you hover over the parameter while writing scripts.
- Type*. The data type accepted or returned by the function. You can:
- Select one of the available BRIX data types from the list: String, Number, Yes/No switch, Date/time, Arbitrary app, App type.
- Use a custom type — to pass or receive data in a format you define, select the Custom type. In the window that appears, select the custom type you created.
- After adding all parameters, click Create.
Next, write the function code on the Scripts tab. To open this tab quickly, you can:
- Click the function name in the Function column of the table.

- Click the function name in the Name column, then in the window that opens, click Open next to the Executable script field.
To delete a function, click its name, then click Delete on the bottom of the page. The function is removed from the list, and its code is automatically deleted from the Scripts tab. You cannot restore a deleted function.
Write the function script for a common script
For each function you create, its name, input parameters, and return value are automatically added to the Scripts tab. Describe the operations to be performed when the function is called.
Write the code in TypeScript. For more information about scripting guidelines for BRIX and available objects and methods, see the BRIX TS SDK documentation.

When you finish configuring the common script, save and publish it.
Step 4. Configure a common script call in another component
After publishing a common script, you can call it from server-side scripts in widgets, business processes, and modules. Configure access in the required component.
Grant a component access to a common script
To access the configured functions and types in a component’s code, add an optional dependency on the module that contains the common script:
- Open the component settings and go to the optional dependencies list:
- For widgets and forms, go to Settings > Available Items in the interface designer.
- For processes, open the Scripts tab and click Settings in the business process designer.
- For modules:
- For API methods, business process actions, or event handlers, go to the Scripts tab and click Settings.
- For a common script, open the Settings tab.
- Add an optional dependency on the module that contains the common script. To do this, click + Add Workspace in the window that opens, select the module, and click Add.
- In the list, assign an alias to the module. The alias must be unique and contain only Latin letters, digits, and underscores. You will use it in the component code.
- Grant access to the module’s common script by clicking the books icon
next to the module name in the list.

- In the window that opens, select the common script from the list and click Add. The script appears under the module name.
- You can also assign an alias to the common script, following the same procedure as for the module.
Import and use a common script in the component code
- In the component settings, go to the Scripts tab.
- Import the common script using the following statement:
import script_name from 'module/common_script'
where:
- script_name is the name used to refer to the common script in the current component’s script.
- 'module/common_script' is the module and common script aliases specified in the optional dependency settings.
- Write the current component’s script, calling the common script functions and using its types.

- Save and publish the component.
The common script functionality will now be available when the current component’s script is executed.