Language:English

WinCC Unified scripting · Problem and fix

Open a pop-up when a PLC tag changes (and why your scheduled task can’t)

PLCPump1_Fault = 0Unified Runtime serverScheduler taskPumpFault_Update()

Base screen script, once per client

Unified Comfort PanelControl room PCLaptop browser
One server, three clients. Switch between the scheduled task and the base screen to see who can actually open the pop-up.

The pump trips, the PLC sets a bit, and you want its detail screen to pop up. The obvious place is a Scheduler task triggered by that bit. It is also the one place where it can never work. Here is why, and three ways that do.

  • Why tasks have no screen, in one picture
  • Three fixes, from no script at all to a tag subscription
  • A ready-to-paste script that works on every client
Start reading

HMIx team6 min readUpdated

What you see

Three versions of the same dead end

You create a task in the Scheduler, trigger it with Tags > Pump1_Fault, and write the obvious line: open the screen Pump1_FaultDetail in a pop-up. Then one of these happens:

  1. TIA Portal refuses to compile the task: Screen and UI are not available in that scope.
  2. It compiles, because the call hides in a global module, and in Runtime nothing opens.
  3. You try to read who is logged on with @UserName inside the task, and it comes back empty.

Avoid· A scheduled task that tries to open a pop-up

// Scheduler > Task "PumpFault", trigger: Tags > Pump1_Faultexport function PumpFault_Update() {  if (Tags('Pump1_Fault').Read()) {    // A task has no screen: on which of your clients should this open?    UI.SysFct.OpenScreenInPopup('FaultPopup', 'Pump1_FaultDetail', false,      'Pump 1 - fault', 240, 120, false);  }}

It is one of the most repeated questions in the Siemens forum, from V16 to V20, and the answer is always the same: it is not a bug, it is the architecture.

Why it fails: a task has no screen

The Scheduler runs on the server; screens live in each client

WinCC Unified is a client-server system. The Runtime server runs the scripts of the screens in one process and the tasks of the Scheduler in another Siemens Tips §2.5. A screen exists once per client: the panel, the PC in the control room, the browser on the maintenance laptop.

A task belongs to none of them. When it asks to open a pop-up, there is no screen to open it on, and no way to know which of the three clients you meant. That is why Siemens forbids it: “No UI functions may be used in scripts or in referenced global modules in the Scheduler.” Siemens readme V18 The same goes for anything that belongs to a session, like the logged-on user.

Three fixes that work

Pick by what you need to show and which version you run

Fig. 1

Which fix is yours?

What should the operator see?

Which WinCC Unified version?

02

Fix 2 · tag subscription

Watch the tag from the base screen: start in Loaded, stop in Unloaded.

Go to the fix
Two questions, one recommendation. All three run in the screen of each client.

1 · Change the screen of a screen window (no pop-up)

If the detail can appear inside the screen instead of floating over it, you need no event at all. Siemens' own example does exactly this for a motor fault: the Screen property of a screen window is dynamized by a script triggered by the state tag, and returns the name of the screen to show Siemens example.

Do this· Screen window > Screen > Script, trigger: Tags > Motor_State

// Screen window "Screen window_1" > Screen > Script. Trigger: Tags > Motor_State// (Siemens' own example: "Triggering a screen change with a tag")export function Screen_window_1_Screen_Trigger(item) {  switch (Tags('Motor_State').Read()) {    case 1:      return 'Screen_MotorFault';    default:      return 'Screen_MotorOk';  }}

2 · Open the pop-up from the base screen (V18 and later)

For a real pop-up, watch the tag from the screen that stays open (your base screen, with the header and the screen window) with Tags.CreateSubscription. Start it in Loaded, stop it in Unloaded, and keep it in the Global definition so both events see it. Every client runs it for itself, so every operator gets the pop-up.

Ready-to-use script

Open a fault pop-up when a PLC tag turns on

Three short parts for the base screen: the subscription in its Global definition, the start in Loaded and the stop in Unloaded. Opens the pop-up on every client, never toggles it closed, and does nothing until the tag changes.

Where it goes
Base screen > Events > Global definition, Loaded and Unloaded
Runs on
WinCC Unified V18 or later

Do this· hmix-fault-popup-from-plc.js

// ---- PART 1 · "Global definition" of the base screen's events ---------// The subscription must live here, outside the functions, so that// Unloaded can stop what Loaded started.let faultWatch;​// ---- PART 2 · Event "Loaded" (paste inside the function TIA writes) ---const FAULT_TAG = 'Pump1_Fault';const POPUP_SCREEN = 'Pump1_FaultDetail';​faultWatch = Tags.CreateSubscription([FAULT_TAG], (changedTags) => {  for (const tag of changedTags) {    // One tag is watched, so its value is all we need (true or 1).    if (tag.Value) {      // toggleOpen = false: a second "true" never closes an open pop-up.      UI.SysFct.OpenScreenInPopup('FaultPopup', POPUP_SCREEN, false,        'Pump 1 - fault', 240, 120, false);

3 · V16 and V17: a script on a screen property

Before V18 there is no tag subscription in scripting. For scripts that belong to the whole screen, Siemens suggests a property of the screen that nobody uses, such as Background > Alternative color, with a tag trigger Siemens Tips §2.2. It runs in the screen, so it may open the pop-up; it just has to return a value for the property.

Do this· Screen > Alternative background color > Script, trigger: Tags > Pump1_Fault

// V16 / V17 (no Tags.CreateSubscription yet): a script on a screen property// that nobody uses, e.g. Background > Alternative color. Trigger: Tags > Pump1_Faultexport function Screen_1_AlternateBackColor_Trigger(item) {  if (Tags('Pump1_Fault').Read()) {    UI.SysFct.OpenScreenInPopup('FaultPopup', 'Pump1_FaultDetail', false,      'Pump 1 - fault', 240, 120, false);  }  return 0xFF000000; // the property still needs a value}

Do this· The task only writes a tag

// The task keeps doing what tasks do well: logic and tags. No screens.export function PumpFault_Update() {  const fault = Tags('Pump1_Fault').Read();  Tags('UI_ShowFaultPopup').Write(fault ? 1 : 0);}

Details that save you a second visit to site

Small parameters, big differences

  1. toggleOpen = false. With true, a second call closes the pop-up that is already open: a flickering fault becomes a pop-up that opens and closes.
  2. parentScreenPath. Leave it empty and the pop-up is global: it survives screen changes. Give it the parent screen's path (./Screen) and it closes with that screen.
  3. Every client opens it. That is usually what you want. If only the control room should, use a session-local internal tag or check the device before opening.
  4. Do not poll. A cyclic script that reads the fault bit every 250 ms would also work, and also slows every screen down. The subscription costs nothing until the bit changes.

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

Can a WinCC Unified scheduled task open a pop-up or change the screen?

No. Tasks run in the Scheduler's process on the server and have no screen or session; Siemens states that no UI functions may be used in Scheduler scripts or in the global modules they reference. Let the task write a tag and let a screen react to it.

How do I open a pop-up from a PLC tag in WinCC Unified?

From V18, create a tag subscription with Tags.CreateSubscription in the Loaded event of the base screen, call UI.SysFct.OpenScreenInPopup when the tag becomes true, and stop the subscription in Unloaded. In V16 and V17, use a script on an unused screen property with a tag trigger.

How do I change the screen when a PLC tag changes?

Dynamize the Screen property of a screen window with a script triggered by the tag that returns the screen name, as in Siemens' example “Triggering a screen change with a tag”. No event or task is needed.

Why is @UserName empty in my scheduled task?

The logged-on user belongs to a client session and a scheduled task runs on the server without one. Read the user in a screen script instead. Siemens also notes that GetRolesFromUser and HasUserRole do not return meaningful values in scheduled tasks.

Will every client open the pop-up?

Yes, when the subscription runs in the base screen: each client runs its own screen scripts. To limit it to one station, decide with a session-local internal tag or a condition per device before opening.

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: SIMATIC WinCC Unified Tips and Tricks for Scripting (JavaScript), entry 109758536, V5.0 (09/2025)
  2. Siemens: Readme TIA Portal V18 Update 5
  3. Siemens: Triggering a screen change with a tag (WinCC Unified V21.1)
  4. Siemens: Opening and closing a screen in a pop-up window (WinCC Unified V21.1)
  5. Siemens: SysFct.OpenScreenInPopup() (WinCC Unified V21.1 object model)
  6. Siemens: Tags.CreateSubscription() (WinCC Unified V21.1 object model)
  7. Siemens: TIA Portal V20 updates readme, WinCC Unified important notes
  • WinCC Unified popup from PLC
  • WinCC Unified scheduled task
  • OpenScreenInPopup
  • change screen from PLC tag
  • Tags.CreateSubscription
  • Task Scheduler
  • TIA Portal