Industrial automation projects are always specialized in their application and industry, making flexibility and adaptability necessary in all forms of programming. This extends not just to PLC controls, but to the HMI screens and devices that operators interact with regularly.
Sometimes, the built-in functions of an HMI platform are not enough to accomplish the desired goal. When creating HMI screens for Unified Basic Panels or Unified Comfort Panels, the use of scripting within components can allow for additional functionality not found in the basic properties of components.
Scripts can allow for more information to be displayed without the addition of PLC logic, such as mathematical expressions involving more than one tag. Scripts can also be used as functions triggered by an event, such as a button press on the HMI. Siemens scripting uses JavaScript and object-oriented principles to allow engineers more flexibility by using an established language for ease of implementation. This blog reviews the basics of WinCC Unified Scripting.
Accessing Scripts – Global Modules and Functions
When developing an HMI program, scripts can be created for use in a variety of ways. To do so, first drill down to the “Scripts” folder in the project tree under the HMI device in your project. From there, select “Add a new global module” to create a container for one or more global functions. Once the global module is created, select “Add a new global function”, which will open the script editor. From here, users can create their own custom functions.

Triggering Global Functions
Once a global function is created within a global module, it can be called in a variety of ways. One method is utilizing the “Scheduled Tasks” feature, which allows a function to run based on a specified condition.
For example, to run the script “Function” when the HMI tag “eStopPressed” changes value, a scheduled task must be created. Once it is created, the default trigger option is “Tags,” which triggers on the value change of an HMI tag. Other trigger options include cycle times ranging from 500ms to one year, as well as alarms. Note that selecting a short cycle time can cause overloads, and that a function triggered by a tag cannot write to the trigger tag.


Once an HMI tag is selected, select the “Events” tab under the task to select the function to run upon trigger. Click the dropdown under the name column to open the menu as shown, and scroll to the bottom to find “Script functions”>”Global module”>”Global module.Function.”

Once a function is selected, choose parameter values to input to the function for this specific run case. These parameters can be several data types, which can be selected using the dropdown in the “Value” column.

Accessing Scripts – HMI Components
HMI components have two main ways to utilize scripts: Events and Dynamic Properties. To have an HMI event trigger a script, first navigate to the HMI component and then to the “Events” tab. Select the preferred trigger event, then click the button shown below to convert the function list to a script.

To use a script to define a component property, first navigate to the component in question and to “Properties.” In the “Dynamization” column, use the dropdown to select Script. This will open a script editor to allow for control of the desired property.


The variable “value” refers to the state of the property scripting for. For example, if I created a script that resulted in “value = 5” for width, the component would display with a width of five pixels. Additional code should always be written between the declaration of the “value” variable and the return.
Script Tools
Siemens offers a few helpful tools as part of the script editor to make it easier to create working code. Some of these tools exist as buttons on the script editor, and some are built-in features, such as:
- Syntax highlighting
- Snippets (code templates)
- System functions
- Referencing HMI objects
- Tooltips
- Autocomplete
- Error marking and correction
- Find and replace

Snippets
Scripting in WinCC Unified component properties includes pre-built sections of code called “Snippets,” which are meant to accomplish a specific, common function without building the script from scratch.
To access snippets, right-click within the script editor to open the menu. From there, you can drill into the HMI Runtime or Logic snippets. HMI Runtime snippets include functions such as opening a faceplate as a pop-up window, writing parameter sets to the PLC, and user management options. Logic snippets include basic structure for if-else statements, for-loops, and more.
Once a snippet is added, review the code block and add or change the items inside to accurately reflect your project. For advanced users, it is possible to create custom snippets following the steps here.

Ready to take your Manufacturing Automation project to the next level? Contact us today to learn more about our solutions and how we can help you achieve your goals.







