Language:English

Guide · WinCC Unified scripting

WinCC Unified script not working? The errors everyone makes

What do you see?

RTIL Trace Viewer · ScriptFW

10:42:01.31 ReferenceError: tags is not defined

Likely causes

Choose the symptom that matches yours. Each one lists the errors that usually cause it.

The script compiles, the button is pressed and… nothing. Or the old value. Or it runs twice. Almost every WinCC Unified script problem we see in forums falls into a dozen families. Pick what you see and go straight to the cause and the fix.

  • Each error with the symptom you see, the cause and the code that fixes it
  • How to make a script tell you what went wrong, on PC and on panels
  • Real messages from the Runtime, decoded line by line
Start reading

HMIx team11 min readUpdated

First, make the script tell you what happened

No alert, no console: the Trace Viewer, the debugger and, in V21.1, script diagnostics

Guessing is the slowest way to fix a script. WinCC Unified gives you three ways to listen, and the first one works on every version and every device.

  1. 01Trace Viewer. Every HMIRuntime.Trace('…') and every script error goes to the trace. Open RTILtraceViewer.exe (in …\Siemens\Automation\WinCCUnified\bin) and filter Subsystem > ScriptFW. On a Unified Comfort Panel, enable the Trace forwarder and connect from the PC.
  2. 02Script debugger (PC only). Enable it in SIMATIC Runtime Manager > Scripts Debugger (port 9222 for screens, 9224 for tasks), restart the Runtime and open chrome://inspect. Your Windows user must belong to the group SIMATIC HMI. To debug a panel project, simulate it on a PC. From V19 Update 2 there is also a Visual Studio Code extension.
  3. 03Script diagnostics (V21.1). A view of the system diagnostics control that lists script errors, overloads and your own traces, on the panel itself.
RTIL Trace Viewer with the Filter menu open on Subsystem and ScriptFW selected
RTIL Trace Viewer filtered by Subsystem > ScriptFW: only script messages remain. Image: Siemens, TIA Portal V21.1 documentation. Original screenshot →

When a script fails, the message tells you more than it seems. This is a real one, taken from Siemens' own documentation:

Script diagnostics view of WinCC Unified V21.1 listing two script errors with the detail of an Uncaught TypeError
The Script diagnostics view (V21.1) with a failed button script and its detail. Image: Siemens, TIA Portal V21.1 documentation. Original screenshot →
Fig. 1

Anatomy of a script error

Engine ExecuteScript Result is empty and error is:
Function: [/screen_modules/::/].[]
Error: /screen_modules/HMI_RT_1::Screen_1/Events.js: 

Tap a part of the message

The path names the device, the screen and the script file; the number after it is the line. Message from the Script diagnostics view, Siemens documentation V21.1.
Chrome DevTools paused on a breakpoint in a WinCC Unified screen script, with the call stack and local scope
The screen debugger in Chrome, stopped on a breakpoint of a button script: (1) navigation area, (2) code, (3) console, (4) debugging area with the call stack and the variables. Image: Siemens, TIA Portal V21.1 documentation. Original screenshot →

Ready-to-use script

Diag: make every script say what it did

A tiny global module with three functions: ok() for a deliberate trace line, fail() that turns any error code or exception into words, and guard() that runs code and reports what it throws. Import it once per screen.

Where it goes
Scripts > Global modules > Diag
Runs on
WinCC Unified V18 or later

Do this· hmix-diag-module.js

// A short success line: where it happened and what happened.export function ok(where, message) {  HMIRuntime.Trace('[' + where + '] ' + message);}​// The reason of a rejected promise or a thrown error, in words.// Siemens: a catch() handler receives either an ErrorCode (a number) or// an ErrorObject (with .ErrorCode); both go to GetDetailedErrorDescription.export function fail(where, reason) {  let text;  if (reason && reason.ErrorCode === undefined && reason.message !== undefined) {    // A JavaScript exception (TypeError, ReferenceError...) thrown by a script.    text = (reason.name || 'Error') + ': ' + reason.message;  } else {    const code = reason && reason.ErrorCode ? reason.ErrorCode : reason;    text = 'error ' + code + ' (' + HMIRuntime.GetDetailedErrorDescription(reason) + ')';

It does not even start

Errors the compiler or the first run reveal

01

Wrong capital letters

What you see

The script stops at the first line. The trace says something “is not defined” or “is not a function”.

ReferenceError: tags is not defined

Why

JavaScript is case-sensitive. tags is not Tags, .read() is not .Read() and Screen.items does not exist. A single letter is enough.

Fix

Copy names from TIA (right-click a property > Copy property name) or let the editor's autocompletion write them. The Siemens object model is all PascalCase: Tags, Read, Screen.Items, Text.

Avoid

const level = tags('Tank1_Level').read();      // ReferenceError: tags is not definedScreen.items('Txt_Level').text = level + ' %';  // items, text: wrong case

Do this

const level = Tags('Tank1_Level').Read();Screen.Items('Txt_Level').Text = level + ' %';
02

Browser habits that do not exist here

What you see

Works in a web page, fails in WinCC Unified: nothing pops up, nothing is logged, the timer never fires.

ReferenceError: alert is not defined

Why

Scripts run on the server in Node.js, not in a browser. Siemens removed alert() on purpose (it would block the operator), and fetch(), XMLHttpRequest, require and file access through Node's fs are not supported.

Fix

Use HMIRuntime.Trace() instead of alert and console, HMIRuntime.Timers.SetTimeout() / SetInterval() instead of the browser timers, HMIRuntime.FileSystem for files, and Open Pipe or the Runtime API to exchange data with other applications.

Avoid

alert('Start pressed');                      // not available in WinCC Unifiedconsole.log('Speed', speed);                 // nowhere to be seensetTimeout(() => Tags('Horn').Write(0), 3000);fetch('http://10.0.0.5/api/orders');         // not supported in Runtime scripts

Do this

HMIRuntime.Trace('Start pressed');           // RTIL Trace Viewer > ScriptFWHMIRuntime.Trace('Speed ' + speed);HMIRuntime.Timers.SetTimeout(() => Tags('Horn').Write(0), 3000);// Data from another system: Open Pipe or the Runtime API (ODK), not fetch.
03

Screen or UI inside a scheduled task

What you see

The task that should open a pop-up or change the screen when a PLC bit changes does not compile, or does nothing.

Why

Tasks run in the Scheduler's process on the server, with no screen and no session. Siemens: “No UI functions may be used in scripts or in referenced global modules in the Scheduler.”

Fix

Let the task write a tag, and let a screen react to it: a dynamized screen window or a tag subscription in the base screen.

Full fix: open a pop-up when a PLC tag changes

It runs, but does the wrong thing

Values from the past, promises shown as text, objects that are not there

04

The read returns the old value

What you see

You write 180 and, in the next line, read 175. A second later the I/O field shows 180.

Why

A write goes to the PLC; the tag image is updated later. Siemens: the following read “will normally return the old value”.

Fix

Do not read what you just wrote: keep the value in a variable and use it. If you need the PLC's confirmation, write with a TagSet and WriteAsync(1) (wait), then check each tag's LastError.

Avoid

Tags('Oven_Setpoint').Write(180);const shown = Tags('Oven_Setpoint').Read(); // still the OLD valueScreen.Items('Txt_Confirm').Text = 'Setpoint: ' + shown;

Do this

const setpoint = 180;Tags('Oven_Setpoint').Write(setpoint);// You already know what you wrote: show that, not a new read.Screen.Items('Txt_Confirm').Text = 'Setpoint: ' + setpoint;
Fig. 2

Why the read is one step behind

ScriptTag imagePLCWrite(180)Read() → 175PLC confirms 180image = 180

The read comes before the update: it returns the old value.

Simplified timeline of a write and an immediate read. Times are illustrative.
05

[object Promise], or nothing at all

What you see

A text field shows “[object Promise]”, or a file, log or database read never reaches the screen and nothing is reported.

Why

File system, logs, alarm queries and databases are asynchronous: they return a Promise, not the data. Without .then the value is never used; without .catch the failure is silent.

Fix

Use the value inside .then() (or await in an async function) and always add .catch() with HMIRuntime.GetDetailedErrorDescription() (V18+).

Avoid

const text = HMIRuntime.FileSystem.ReadFile('C:\\Users\\Public\\batch.txt', 'utf8');Screen.Items('Txt_Batch').Text = text;   // shows [object Promise]

Do this

HMIRuntime.FileSystem.ReadFile('C:\\Users\\Public\\batch.txt', 'utf8')  .then((text) => {    Screen.Items('Txt_Batch').Text = text;  })  .catch((reason) => {    HMIRuntime.Trace('[Batch] ' + HMIRuntime.GetDetailedErrorDescription(reason));  });
06

Cannot set properties of undefined

What you see

The property never changes and the trace shows a TypeError on the line that sets it.

TypeError: Cannot set properties of undefined (setting 'Visible')

Why

Screen.FindItem() returned nothing: a screen name in the path, a relative path from the wrong screen window, // after a main screen window was defined, or an object of a pop-up that has not loaded yet.

Fix

Check the path rules and find the object where it really exists.

Full fix: FindItem returns undefined
07

A variable that “forgets” its value

What you see

An event sets a variable, and a property script of the same screen still sees the old value. Or the value is gone after a screen change.

Why

Each screen has two script contexts, properties and events, and each gets its own copy of the variables in its global definition. A screen change discards them.

Fix

Keep shared state in an internal HMI tag (scope Local session if every client needs its own) or, for script-only data, in a DataSet (HMIRuntime.UI.DataSet lives for the browser session).

Avoid

// Events > Global definitionlet selectedMotor = 0;// Button event: selectedMotor = 3;// A property script of the same screen reads selectedMotor... and sees 0:// properties and events are two separate script contexts.

Do this

// Keep shared state in an internal HMI tag (scope "Local session" if each// client should have its own), never in a JavaScript variable.Tags('UI_SelectedMotor').Write(3);// Any property, event or other screen reads it:const motor = Tags('UI_SelectedMotor').Read();

It works in simulation, not on the panel

Same script, different device, different rules

08

Works on the PC, fails on the Comfort Panel

What you see

The project runs fine in simulation or on a Unified PC; on the panel, a file is never written, a button reacts only to the mouse, a program does not start.

Why

Files: on a Unified Comfort Panel scripts may only create files under /home/industrial, or on the SD card and USB sticks (/media/simatic/X51, X61…). Network drives are not supported.

Touch: Siemens warns that the Press key and Release key events are not executed during touch operation.

Programs: StartProgram on a panel only starts its predefined applications, and not from a scheduled task.

Debugging: the script debugger is PC only.

Fix

Use click and press/release mouse events for touch buttons, absolute Linux paths on the panel, and test file scripts on the real device.

Full fix: writing CSV files on PC, panel and USB

It runs twice, forever, or too slowly

Triggers that fire more than you think

09

The script runs twice (or never stops)

What you see

A counter goes up by two, a message is logged twice when the screen opens, or the CPU climbs and never comes down.

Why

In V17, a trigger tag that is also shown on the screen fired twice on loading: once for the initial value, once for the PLC value. From V18 the initial value (quality 0x4C) no longer triggers.

A Bool trigger fires on both edges: true and false.

A script that writes its own trigger tag starts itself again: an endless loop. Tags (automatic) makes it easy to do by accident.

Fix

Check the value, not only the change (if (value === true)), never write a trigger tag inside its own script, and pick trigger tags by hand.

Avoid

// Trigger: Tags > Counterexport function Txt_Counter_Text_Trigger(item) {  const count = Tags('Counter').Read();  Tags('Counter').Write(count + 1); // writes its own trigger: endless loop  return String(count);}

Do this

// Trigger: Tags > Counter. Read, show, never write the trigger tag.export function Txt_Counter_Text_Trigger(item) {  return String(Tags('Counter').Read());}
10

“Overload: Script … is rejected”

What you see

Screens react late, buttons lag, and the trace shows overload messages.

Overload: Script <name> is rejected

Why

User scripts wait in one low-priority queue in a single thread. Short cyclic triggers on many objects fill it faster than it empties, and Siemens rejects the excess.

Fix

Replace cyclic triggers with tag triggers, merge scripts that share a trigger, read with TagSets, and move periodic work to the Task Scheduler.

How to keep scripts fast (best practices)

Code copied from somewhere else

Comfort panels, WinCC V7 and chatbots speak other dialects

11

VBScript or invented functions

What you see

A script that “worked on the old panel”, or that a chatbot wrote, is full of errors, or calls functions that sound right but do not exist.

Why

WinCC Comfort/Advanced and WinCC V7 use VBScript or C with another object model (SmartTags, HMIRuntime.Tags("…").Write in VB). Siemens' migration guide is clear: scripts must be recreated in JavaScript. General chatbots fill the gaps with plausible names such as Tags.Subscribe or SetTimer.

Fix

Check every call against the Siemens object model for your version, or use a tool that does it for you.

Avoid

' VBScript from a Comfort panel: will not even compile in UnifiedSmartTags("Motor_Start") = 1// ...or an "AI" answer that sounds right but does not exist:HMIRuntime.Tags.Subscribe('Motor_Start', onChange);HMIRuntime.Timers.SetTimer(onTick, 1000);

Do this

Tags('Motor_Start').Write(1);// Real Siemens functions (object model): watch a tag from V18 on...const watch = Tags.CreateSubscription(['Motor_Start'], onChange);watch.Start();// ...and timers live under HMIRuntime.Timers:const timerId = HMIRuntime.Timers.SetInterval(onTick, 1000);

Three ways HMIx saves you the trial and error

  1. 01

    Describe what the script must do. HMIx asks for your tags, writes it, explains it part by part and simulates it.

  2. 02

    Paste a script you already have. HMIx explains it and flags, for free, the classic errors.

  3. 03

    Something fails? HMIx walks you through the checks, from the trace message to the fix.

Frequently asked questions

Why does my WinCC Unified script do nothing?

Usually because it fails at its first error and the failure is only written to the trace. Open the RTIL Trace Viewer, filter Subsystem > ScriptFW and run the script again: the message names the screen, the script and the line. Wrong capital letters, browser functions such as alert, and objects not found are the most common causes.

How do I see console.log output in WinCC Unified?

You do not: use HMIRuntime.Trace() instead and read it in the RTIL Trace Viewer (Subsystem > ScriptFW), in the Chrome script debugger on a PC Runtime, or in the V21.1 Script diagnostics view.

Why does Tags().Read() return the old value after a Write()?

The write is sent to the PLC and the tag image is updated afterwards, so a read in the same script normally returns the previous value. Use the value you wrote, or write with a TagSet and WriteAsync with wait to get the PLC's confirmation.

Why does my script work in simulation but not on the Unified Comfort Panel?

Panels have their own rules: scripts may only write files under /home/industrial or on SD and USB media, the Press key and Release key events are not executed with touch, StartProgram only starts the panel's own applications, and the script debugger is not available on the panel.

What does “Overload: Script … is rejected” mean?

User scripts are processed one by one in a single low-priority queue. When short cyclic triggers start scripts faster than they finish, the Runtime rejects the excess. Use tag triggers, fewer and merged scripts, TagSets, and move periodic work to the Task Scheduler.

Can I convert my WinCC Comfort VBScript to WinCC Unified?

Not automatically: WinCC Unified uses JavaScript with a different object model, and Siemens’ migration guide says the scripts must be recreated. HMIx can help: describe in the chat what the old script did (you can paste it as a reference) and HMIx writes the JavaScript version for WinCC Unified and explains it part by part.

Ready to use, from the HMIx catalogue

Free to download: this article’s script, shared from HMIx, and controls for the screen around it.

Browse the free catalogue →

Sources

Every Siemens statement in this article was read in the document linked here. Versions and behaviour can change with updates: check the manual of your own version.

  1. Siemens: Tracing with the RTIL Trace Viewer (WinCC Unified V21.1)
  2. Siemens: Enabling the debugger (WinCC Unified V21.1)
  3. Siemens: Configuring script diagnostics (WinCC Unified V21.1)
  4. Siemens: Reading ErrorCodes and ErrorObjects (WinCC Unified V21.1)
  5. Siemens: Runtime scripting, General information (WinCC Unified V21.1)
  6. Siemens: SIMATIC WinCC Unified Tips and Tricks for Scripting (JavaScript), entry 109758536, V5.0 (09/2025)
  7. Siemens: WinCC Unified Runtime system manual, 11/2023 (V19)
  8. Siemens: Readme TIA Portal V18 Update 5
  9. Siemens: Guide for migrating to WinCC Unified, 3.4.8 Scripts
  10. Siemens: Engineering guideline for WinCC Unified, entry 109827603, V4.0 (11/2025)
  • WinCC Unified script not working
  • WinCC Unified script error
  • RTIL Trace Viewer
  • script debugger
  • TypeError
  • ReferenceError
  • TIA Portal
  • JavaScript