Which script runs where
YTCC has two kinds of scripts. Client scripts belong to the screens: they run in the browser of whoever has the page open, for screen behavior and operator actions. Server scripts belong to the plant: they run on the server, whether or not anyone is looking, for calculations and unattended automation. Both are written in JavaScript; server scripts in TypeScript.
Comparison
| Client script | Server script | |
|---|---|---|
| Runs in | The browser, on the run screen and in the Run mode of the screen editor; not while you edit | A separate process on the server for each enabled script |
| Runs when | A page opens or closes, periodically (every 500 ms or more), when a signal changes, or when an operator acts on an object (click, input…) | A signal changes, an alarm occurs, a condition becomes true, on a schedule, when the script stops |
| Runs as | The signed-in user: a write is an ordinary command with that user's permissions, responsibility areas and the command log | The script itself (script:<name> in the command log), with its own permission to command the field, target patterns and a rate limit |
| Can reach | Signals, the objects and pages of the screen, popups, messages, maps, communication control | Signals and alarms through its ctx interface; no screen, no files, no network, no programs |
| Keeps state | Only while the page is open | Persistent state that survives a restart |
| Limits | No time limit; a warning after 5 seconds | Memory, time per call and commands per minute are limited; a script that keeps failing is stopped |
| Edited in | The screen editor, Code view | The configuration editor, Automation › Server scripts |
Which to use
| Task | Script |
|---|---|
| Show or hide objects, change texts and colors from logic that does not fit an animation | Client |
| Ask the operator for confirmation or a value before a command, open a popup, go to a page | Client |
| A button that sends several commands in a row on behalf of the operator | Client (the operator's permissions apply) |
| A calculated value that must exist even when no screen is open, for example a daily total | Server |
| An automatic reaction to a signal or an alarm, an interlock in software, a schedule | Server |
| Anything that must keep working when the operator closes the browser | Server |
Prefer the declarative tools before a script: animations and bindings on objects, click actions, expression signals and alarm definitions. They are checked, translated and easier to maintain; use a script for what they cannot do.
Client scripts are not a security boundary
A client script runs in the operator's browser. It cannot do more than the signed-in user may do: every write goes to the server, which checks the permissions and the interlocks again. But a client script is not isolated from the page: whoever may edit scripts may run code on the operators' screens. Give the Editor access permission only to engineers.
For how to write them, see Client scripts; for the server side, see Server scripts.