WinCC Global vs Local Scripts: Client-Server Execution Guide
Script execution context in a Siemens WinCC server-client runtime is one of the most commonly misunderstood areas of HMI engineering. A global script is not the same as a script that runs everywhere, and a local script is not the same as a script that runs only on the client. The actual execution model depends on three orthogonal factors: where the script is stored in the project tree, what triggers the script, and what type of tag or variable fired that trigger. This reference clarifies the model, explains how server-client propagation works, and provides a verified pattern for a per-station authorization script that does not cross-contaminate other clients.
1. Script Storage vs Script Execution Context
WinCC projects contain three primary script containers, and the location of a script determines how it can be called - but it does not, by itself, determine where it runs.
| Container | Editor | Visibility | Default Execution Site |
|---|---|---|---|
| Project-wide (Global) | Global Script editor (V7) / Scripts editor (Unified) | All computers in the project | Wherever a trigger fires |
| Computer-local (Actions: Station) | Computer properties → Actions | One specific computer | That specific computer only |
| Picture-local | Screen object events / Dynamic dialogs (C / VBS) | Where the picture is loaded | The station displaying the picture |
A script that lives in the global script editor is globally visible: any client or server in the project can reference it by name. A script that lives in a computer's Actions: Station list is visible only to that computer and never propagates. The execution site is governed by the trigger source, not by the storage location.
2. Trigger Types and Propagation
WinCC scripts run in response to a trigger. The two trigger categories you must distinguish are:
- Project tag trigger - the tag is part of the project tag list and is replicated to every configured computer.
- Computer-local tag trigger - the tag exists only on one specific computer and is not visible to the others.
When a project tag changes value, every computer that subscribed to that tag receives the update. If a global script is bound to that tag, every computer evaluates the change locally. The script body runs on each subscribed computer, not on a single shared engine.
When a computer-local tag changes, only the owning computer sees the change. A global script bound to that computer-local tag will only execute on the owning computer, because no other computer can ever observe the trigger event.
3. Server-Client Topology Model
The reference topology for this article is a single WinCC server hosting the project, with one or more WinCC clients connected as either standard clients or web clients. The server owns the canonical tag image; clients hold a redundant copy used for local screen updates.
In this topology, an action stored under Global Script and triggered by a project tag will run once on the server and once on each subscribed client. An action stored under Client 1 → Actions: Station will only run on Client 1 regardless of trigger type.
4. Execution Behavior Matrix
The table below maps the four practical combinations of (script location) x (trigger type) to the resulting execution footprint.
| Script Location | Trigger Type | Executes On | Typical Use |
|---|---|---|---|
| Global Script editor | Project tag change | Server + every subscribed client | Synchronized color/visibility updates, alarm acknowledgements |
| Global Script editor | Computer-local tag change | Owning computer only | Per-station authorization after login |
| Computer: Station actions | Project tag change | That computer only (script never reaches the others) | Server-only side effects (file write, archive cleanup) |
| Computer: Station actions | Computer-local tag change | That computer only | Local UI behavior not shared with the project |
5. Cyclic vs Event-Triggered Execution
Every script action has a trigger configuration dialog. The trigger can be:
- Tag trigger - fires on value change or on a configurable threshold.
- Cyclic trigger - fires every N seconds, with a configurable time base (250 ms, 500 ms, 1 s, 5 s, 10 s, 1 min, 5 min, 10 min, 1 h, user-defined).
- Event trigger - picture open/close, keyboard event, mouse event, alarm event, language switch.
A cyclic trigger on a global script bound to a project tag is the highest-risk configuration: it will execute on the server and on every client at the configured interval, multiplying CPU load by the number of stations. For an eight-client system with a 1 s cyclic, you generate 9 script executions per second. For an authorization script that only needs to run once per login, this is wasteful and causes race conditions on the user-rights array.
6. Authorization Script Pattern (Per-Station)
The most common real-world use case is a per-station authorization routine that runs immediately after a user logs in on a particular client. The script inspects the current operator name, looks up group memberships, and writes the result into a computer-local internal tag set that the screen navigation uses to enable or disable buttons.
The correct implementation, in WinCC V7 VBScript inside a global script action, uses a computer-local tag as the trigger and writes only to computer-local authorization tags. The script body is identical on every station, but the trigger is local, so execution is local.
' Global Script action: Auth_RefreshLocalRights
' Trigger: Computer-local internal tag "@Local_LoginEvent" (rising edge, internal)
' Writes to computer-local tags: @Local_UserLevel, @Local_MaintAllowed, @Local_AdminAllowed
Dim sUser, iLevel
sUser = HMIRuntime.Tags("@CurrentUser").Read
iLevel = 0
Select Case UCase(sUser)
Case "OPERATOR_A" iLevel = 1
Case "MAINT_USER" iLevel = 2
Case "ADMIN" iLevel = 3
Case Else iLevel = 0
End Select
HMIRuntime.Tags("@Local_UserLevel").Write iLevel
HMIRuntime.Tags("@Local_MaintAllowed").Write (iLevel >= 2)
HMIRuntime.Tags("@Local_AdminAllowed").Write (iLevel >= 3)
The tags prefixed with @ are WinCC internal tags. @CurrentUser is a system tag and is replicated; the three @Local_* tags must be defined as computer-local internal tags in each client's tag management. When the user logs in on Client 2, only Client 2's @Local_LoginEvent changes, only Client 2's script instance fires, and only Client 2's authorization tags update.
@Local_UserLevel as a project tag. The first client to log in will overwrite the tag for every other client, granting or revoking rights across the entire fleet. The "global" portion of the trigger propagation model only protects you when the trigger itself is local.7. Picture-Local Script Trigger Model
Scripts attached to picture objects (for example, the Click event of a button) run in the runtime context of the station that is currently displaying the picture. If the picture is the server's start picture, the script can only fire on the server. If the picture is replicated to all clients (which is the default for base screens in a distributed system), the script logic is replicated with it and will fire on whichever station the user clicks the button.
For an authentication button that opens a login window, the canonical pattern is:
- Place a base picture
LoginScreen.pdlon the server with a button "Login". - Replicate the picture to all clients via picture assignment.
- On the button's Click event, call the global function
OpenLoginWindow(). - The function lives in the global script editor and uses
HMIRuntime.Screensto openLogin.pdlon the local station.
This pattern gives you a single copy of the screen logic but a station-local execution footprint - exactly the right behavior for per-station user logins.
8. TIA Portal V20 Runtime Unified Differences
In TIA Portal V20 Runtime Unified, the scripting model moves away from VBScript to JavaScript-based scripts and reorganizes the project tree. The concepts still map cleanly:
| WinCC V7 Concept | Runtime Unified Equivalent (V20) |
|---|---|
| Global Script editor (VBScript) | Project library → Scripts (JavaScript) |
| Actions: Station | RT Unified station → Scheduled tasks / Local scripts |
| Computer-local internal tag | Tag with "Local" scope at the device |
| HMIRuntime.Tags("X").Read | Tags("X").Read() |
For Unified, the documentation describes a global definition inside a local script: when the global definition area of a global script is used, the script context in which the global script is executed is relevant. This means that a global function that references local data must be invoked from a script context that has access to that local data. The same trigger-propagation logic applies: a Unified global script bound to a local HMI tag fires only on the local HMI; bound to a shared tag, it fires on every subscribing runtime. See the official manual page Creating a global definition in a local script (RT Unified, V20) for the binding rules.
9. Best Practices Checklist
-
Name by intent, not by location. Prefix actions that must run everywhere with
Global_and prefix per-station actions withLocal_. Reviewers should be able to read the prefix and predict the execution footprint. - Use computer-local internal tags as the trigger when you need per-station behavior. Do not rely on a project tag with conditional logic that early-returns unless the script is local-only by design.
- Keep authorization writes in computer-local tags. Never write a user-rights bit into a project tag that other clients will overwrite.
- Prefer event triggers over cyclic triggers for stateful operations. Cyclic scripts run even when nothing has changed and burn CPU on every station.
- Inspect the GSC Runtime window during commissioning. The GSC (Global Script C) and GSR (Global Script Runtime) tools list every action, its trigger, and its last execution timestamp. Use this to confirm the action is firing on the intended stations only.
- Document the trigger tag type. In a code comment, state whether the trigger is a project tag or a computer-local tag. The runtime will not warn you if you bind a global action to a project tag when the design intent was local.
10. Verification Procedure
After configuring any script that you expect to execute per station, verify the footprint with this procedure:
- Open the GSC Runtime on the server and on one client.
- Force the trigger tag to change on the test client (use the Tag Simulator or a button bound to the local tag).
- Confirm the action's last-execution timestamp advances on the test client only.
- Repeat on a second client to confirm the action does not fire there.
- For a project-tag-triggered global action, perform a single tag change and confirm the timestamp advances on every station, including the server.
If a per-station action fires on multiple stations, the trigger tag is project-scoped - move it to the computer-local internal tags group. If a synchronized action fires on only one station, the trigger tag is local - re-evaluate whether you actually need global behavior.
11. Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| Login on Client A immediately changes the operator level on Client B | Authorization tag is a project tag, not computer-local | Move @Local_UserLevel and related tags to the client's internal tag group |
| Global action never fires | Trigger tag is computer-local on a different station | Move the trigger tag to the project scope or change the action to a Station action on the owning client |
| High CPU on every client with low CPU on the server | Global action has a 250 ms cyclic trigger on a project tag | Switch to event trigger or raise the cyclic interval to 1 s+ |
| Script runs but reads stale user name | @CurrentUser read before the login event finished propagating | Delay 200 ms after the login event or trigger the action on the "logged in" event tag, not the "click" event |
| Picture button works on the server but not on a client | The function called is a Station action on the server, not a global function | Move the function to the global script editor or replicate the Station action to the client |
12. Summary Decision Table
| Goal | Container | Trigger Type | Write To |
|---|---|---|---|
| Synchronized alarm color across all clients | Global Script | Project tag (alarm state) | Project tag (display flag) |
| Per-station authorization after login | Global Script (function) | Computer-local tag (login event) | Computer-local internal tags |
| Server-side daily archive cleanup | Server Station actions | Cyclic (daily at 02:00) | File system (no tag write) |
| Button that opens a per-station popup | Picture event (replicated) | Click event | Local screen call |
Does a WinCC global script always run on the server?
No. A global script runs wherever its trigger fires. If the trigger is a project tag, the script runs on the server and on every subscribed client. If the trigger is a computer-local tag, the script runs only on the computer that owns that tag.
What is the difference between a Global Script and a Station Action?
A Global Script lives in the project-wide script editor and is visible to every computer. A Station Action lives under a specific computer's "Actions" list and is visible only to that computer. Both use the same trigger and execution model; only the visibility differs.
How do I make an authorization script run only on the station where the user logs in?
Bind the script trigger to a computer-local internal tag (for example, an @Local_LoginEvent tag) and write the resulting user-level bits to other computer-local internal tags. Avoid using project tags for the trigger or for the authorization outputs, otherwise the first login will overwrite the rights on every other client.
Why does my cyclic global script burn CPU on every client?
A global action with a cyclic trigger and a project-tag scope will run on the server and on every subscribed client at the configured interval. For an eight-client system with a 1 s cycle, that is 9 script executions per second. Switch to an event trigger or raise the cyclic interval if the operation does not need second-level resolution.
Does the TIA Portal V20 Runtime Unified model behave the same way?
Yes, the trigger-propagation rules are equivalent. A Unified global script bound to a local HMI tag fires only on the local runtime; bound to a shared tag, it fires on every subscribing runtime. The JavaScript-based API and the Scripts editor in the project library replace the VBScript Global Script editor, but the per-station vs. global distinction is preserved. See the official V20 Runtime Unified scripting documentation for binding details.