Skip to main content

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 scriptServer script
Runs inThe browser, on the run screen and in the Run mode of the screen editor; not while you editA separate process on the server for each enabled script
Runs whenA 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 asThe signed-in user: a write is an ordinary command with that user's permissions, responsibility areas and the command logThe script itself (script:<name> in the command log), with its own permission to command the field, target patterns and a rate limit
Can reachSignals, the objects and pages of the screen, popups, messages, maps, communication controlSignals and alarms through its ctx interface; no screen, no files, no network, no programs
Keeps stateOnly while the page is openPersistent state that survives a restart
LimitsNo time limit; a warning after 5 secondsMemory, time per call and commands per minute are limited; a script that keeps failing is stopped
Edited inThe screen editor, Code viewThe configuration editor, Automation › Server scripts

Which to use​

TaskScript
Show or hide objects, change texts and colors from logic that does not fit an animationClient
Ask the operator for confirmation or a value before a command, open a popup, go to a pageClient
A button that sends several commands in a row on behalf of the operatorClient (the operator's permissions apply)
A calculated value that must exist even when no screen is open, for example a daily totalServer
An automatic reaction to a signal or an alarm, an interlock in software, a scheduleServer
Anything that must keep working when the operator closes the browserServer

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.