Table of contents
Legal information ..................................................................................................... 2
1 Introduction .................................................................................................... 5
1.1 Overview ........................................................................................... 5
1.2 Components used ............................................................................. 5
2 General............................................................................................................ 6
2.1 System function or script (a decision-making aid) ............................... 6
2.2 Trigger types ..................................................................................... 6
2.3 Access properties of a screen object .................................................. 8
2.4 Difference between synchronous and asynchronous script calls......... 8
2.5 Script threads .................................................................................. 10
3 Configuring scripts ...................................................................................... 11
3.1 Configuring local scripts ................................................................... 11
3.1.1 Dynamizing object properties via scripts .......................................... 12
3.1.2 Calling up scripts via events ............................................................. 13
3.1.3 Calling scripts via Scheduled tasks .................................................. 13
3.2 Configuring global script modules .................................................... 14
3.2.1 Add global module ........................................................................... 15
3.2.2 Creating a Global Definition Area ..................................................... 16
3.2.3 Edit global functions......................................................................... 17
3.2.4 Import and use content from global modules .................................... 19
4 Tips and tricks for creating scripts (JavaScript in general) ....................... 24
4.1 Strings in JavaScript ........................................................................ 24
4.1.1 Linking strings by script.................................................................... 24
4.1.2 Adding spaces to linked strings ........................................................ 24
4.1.3 Determining the length of a string .................................................... 25
4.1.4 Finding a sub-section of a string ...................................................... 25
4.1.5 Turning a string into an array ........................................................... 25
4.2 Arrays in JavaScript ......................................................................... 26
4.2.1 Creating arrays and accessing array elements ................................. 26
4.2.2 Extending and truncating arrays ....................................................... 27
4.2.3 Sorting arrays .................................................................................. 27
4.2.4 Turn arrays into strings .................................................................... 28
4.3 Math object in JavaScript ................................................................ . 28
4.3.1 Add constants .................................................................................. 29
4.3.2 Round off tag values ........................................................................ 29
4.3.3 Find square root .............................................................................. 29
4.3.4 Use exponent function ..................................................................... 29
4.3.5 Generate random number ................................................................ 30
4.3.6 Find minimum/maximum values ....................................................... 30
5 Tips and tricks for scripting (WinCC Unified specific)............................... 31
5.1 Script snippets ................................................................................. 31
5.2 Description of the "HMI Runtime" snippets ....................................... 32
5.3 Performance-optimized configuration ............................................... 34
5.3.1 Prefer system dialogs ...................................................................... 34
5.3.2 Read multiple tags with TagSet........................................................ 34
5.3.3 Avoid cyclic scripts .......................................................................... 35
5.3.4 Establish database connections once .............................................. 35
5.4 Screens and screen objects ............................................................. 36
5.4.1 Finding objects in screen windows with object paths ........................ 36
5.4.2 Screen change across multiple screen windows .............................. 39
5.4.3 Displaying screens as pop-ups ........................................................ 40