Skip to main content

Script Management

Script management is used to maintain runtime scripts for gateways. Scripts can be used for variable data conversion, memory variable calculation, data forwarding templates, dynamic SQL (custom entry statements or table structures), MQTT RPC (MQTT reverse write or query requests), and other scenarios. After saving the script, it must be compiled successfully for related functions to use the latest content.

First, look at terminology

terminologyOn-site understanding
scriptInternal reusable calculation or conversion logic within the gateway is used to process variable values, generate uploaded content, or handle external requests.
CompileCheck whether the script can be run by the gateway. When compilation fails, relevant variables, rules, or forwards will not use new content.
Data ConversionConvert the original equipment values into engineering values required on site, such as scale conversion, unit conversion, and status text conversion.
Memory variable scriptsScripts for calculating internal variables of the gateway, which do not read directly from the PLC but read existing variables or internal states.
Dynamic models / templatesGenerate uploaded content in formats specified by external systems, such as custom JSON fields, device fields, or alarm fields.
Dynamic SQLCustom statements or table structures written into the database, commonly used in scenarios where fixed-width tables or special field naming are required in projects.
MQTT RPCreceives write, query, or control requests from external systems via MQTT, and is parsed and returned by scripts.
Complete codeAdvanced extension methods. You need to understand C# code and its operational impact; for regular field configurations, it's not recommended to start here.

Page Entry

After logging into GatewayRuntime Web, click the "Development Configuration → Script Management" menu on the left.

Script Management Page

Page Structure

AreaDescription
Local ScriptsMaintains scripts saved at the current runtime, supporting addition, editing, compilation, deletion, and batch operations.
Loaded scriptView scripts that are already accessible to the gateway, displaying information such as name, class, type, and data type in read-only.
Name SearchFilter the list by script name.
Category FilteringFiltering by script category, local categories come from saved scripts.
Type FilteringFiltering by script type, such as data transformation, memory variable, MQTT RPC.
Tool buttonsOrder: Add, batch compile, batch delete, refresh; For the batch button, you need to check the script first.

List Field

FieldDescription
NameThe script's unique name in the system.
ClassificationUsed to organize scripts by business, device, or purpose, which can be empty.
TypeScript expression type, which determines the editor template, available inputs, and subsequent references.
Update TimeThe last time the library was saved or compiled and written.
OperationsEdit, compile, or delete the current script.

Create a new script

Click the 'Add Script' button in the top right corner of the list to open the "New Script" popup.

New Script Dialog

Configuration ItemsDescription
Script NameRequired. It is recommended to use English, numbers, and underscores. After saving names, they will be referenced by variables, rules, data forwarding, or RPC configurations, so frequent modifications are not recommended.
Script TypeRequired. After selecting, a corresponding writing prompt will appear at the bottom of the pop-up window.
ClassificationOptional. You can select an existing category or directly enter a new category.
Descriptionoptional. Record script usage, citation locations, and maintenance precautions.
Type DescriptionRead-only prompt explaining the purpose and writing requirements of the current script type.

After clicking "OK," the system will create a script and automatically enter the script editor.

Script Type

TypeApplicable Scenarios
Data ConversionPerform unit conversion, formatting, range mapping, or state transformation on the original values of collected variables.
Memory VariablesCompute memory variables, which can be read from other variables to generate derived results.
Dynamic Model - Variable DataConverts variable data into custom upload objects.
Dynamic Model - Device DataConverts device status into a custom upload object.
Dynamic Model - Alarm VariableTransforms alarm data into a custom upload object.
Dynamic Model - Plugin EventConverts plugin event into a custom upload object.
Dynamic SQL-*Customizable inscription logic by variable, device, alarm, or plugin event dimension.
MQTT RPCprocesses MQTT RPC messages, suitable for write scenarios where message parsing and organizing responses as agreed on the site are required.
Complete CodeWrite complete C# code suitable for advanced extensions. Before use, confirm the compilation requirements and operational impact.

Script Editor

The Script Editor includes the top operation bar, code editing area, and bottom information panel.

Script Editor Page

AreaDescription
Back ButtonReturn to Script List. Unsaved content should be compiled and saved first.
Script Name TagDisplays the current script name, classification, and script type.
Compile and save themain button on the top right. Execute the compilation, and after success, save the script and load the compilation result.
Code editingMaintains C# code, supporting syntax highlighting, undo, redo, and comment switching.
Bottom panelcontains tabs for "Compilation," "Node Information," and "Input Parameters."

Bottom tab

tabDescription
Compilation logDisplays compilation process, errors, warnings, and success information. Clicking on errors or warnings can locate the corresponding code location.
Node informationMaintenance script names and categories. After modification, compilation and saving are required for persistence.
Input parametersOnly the types "Data Transformation" and "Memory Variable" are displayed. Used to define configurable parameters.

Enter parameter field

fieldDescription
Parameter nameParameter identifier, read by this name in the script.
Data typeParameter value type. For numbers, select integer or decimal type; for switches, select boolean type; for text, select string; for time, select date and time; It should match the actual input values in the script.
Initial valueparameter default; if left blank, it is treated by type by default.
DescriptionParameter usage description for easier subsequent maintenance.

Compilation Log

After clicking "Compile and Save" at the top, the "Compilation Log" tab at the bottom will display the complete process.

Script Editor Compiles Logs

Log EntriesDescription
Start Compiling ScriptsMark the start of this compilation and display the script name.
Script TypeDisplays the current expression type, such as "Data Transformation".
Compilation successfulmeans the script has been compiled.
Compilation OutputDisplays compiled output information for on-site troubleshooting of loading issues.
Error/Warning StatisticsThe number of errors and warnings is displayed on the right side of the bottom panel.

If compilation fails, the red error should be handled first; Warnings do not necessarily prevent compilation, but it is recommended to address them before going live.

Common Operations

OperationsSteps
Edit ScriptClick "Edit" in the list, enter the editor, modify code or parameters, then click "Compile and Save".
Single CompilationClick "Compile" in the list, which is suitable for quickly verifying whether existing scripts can still be compiled.
Batch CompilationCheck multiple scripts and click the Batch Compilation button on the toolbar. Commonly used for unified verification after upgrades.
Delete the scriptClick "Delete" and confirm. Before deletion, confirm that the script is no longer referenced in variables, data forwarding, MQTT RPC, or rules.
View Loaded ScriptsSwitch to the "Loaded Scripts" tab to confirm the currently available expressions at runtime.

Use Note:

ScenariosRecommended
Script NamingUse stable naming and avoid frequent renaming. Variables, rules, data forwarding, and RPC configurations may be referenced by script name.
Production modificationBefore modifying the production environment script, export the configuration or record the original script content.
Compilation failureCheck the first error in the compilation log; usually, subsequent errors are chain results.
The loaded list is emptyFirst confirm that the script has been successfully compiled, then refresh the "Loaded Scripts" tab.
AOT ReleaseIn AOT scenarios, dynamic compilation capabilities may be limited by the release method, so script verification should be completed before release.