IMDTouchKnowledge BaseShop main store

Explainer

Why a WinCC Unified V19 script cannot read an HMI array at once

HMI and touchscreens Published 6 min read By IMDTouch engineering team

Short answer

In WinCC Unified V19 the Read method on an array tag is only supported for addressed elements, so Tags("ArrayVariable").Read() fails or gives unreliable results. Read Tags("ArrayVariable[2]") style elements in a loop, write complete arrays with a TagSet for consistency, and use the V20 BlockArrays type for documented whole-array reads.

On this page
  1. Why does Tags("ArrayVariable").Read() not return a whole array in V19?
  2. Which array type works in which runtime version?
  3. How do you read a single array element from a V19 script?
  4. How do you read the whole array when V19 only supports elements?
  5. How do you write all array elements at once?
  6. What breaks if you copy an external array element by element?
  7. How do you test array access before deploying the script?
  8. Do you upgrade to V20 or rework the V19 script?
  9. Questions asked

In WinCC Unified V19, calling the Read method on the parent array tag does not return a usable JavaScript array: the documented Read method on an array that is not configured as an array-as-block only supports individual array elements, and Siemens explicitly says not to call it on the higher-level array. The fix is to read addressed elements such as Tags("ArrayVariable[2]").Read() and build the local array yourself.

Why does Tags("ArrayVariable").Read() not return a whole array in V19? #

A parent-array read fails at the HMI tag boundary, before any JavaScript array function can help, because the V19 runtime does not support converting the configured HMI array into one script object. A JavaScript array is an object in script memory; an HMI array tag is a configured group of indexed values, and the Read method is the bridge between them. When the bridge does not exist for the whole tag, assigning the result to a variable named array does not create an array or fetch the missing elements.

The behavior is also not consistently a hard error. In some V19 configurations a parent-array read appears to work, which is why the February 2024 procedure describing whole-array reads circulated without an immediate correction. Configuration-dependent success is not a basis for a portable script: the supported V19 path is element access only.

Which array type works in which runtime version? #

Element-addressed reads work on scalar arrays in V19 and later; documented whole-array reads exist only for the BlockArrays tag type introduced in V20. That is a type distinction, not an upgrade promise. Moving the project to V20 does not make every existing array readable as one object; it gives you a tag type whose documented purpose is to treat the entire array as a single data block.

The decision table:

Situation Mechanism Decision
V19 project, scalar array, whole-array read fails Element access is supported, parent-array read is not Read addressed elements in a loop
V19 project, whole-array read seems to work Configuration-dependent behavior hides the unsupported boundary Keep element reads for a repeatable implementation
Local array functions work on literals but fail after an HMI read Script execution and tag conversion are separate operations Fix the read path, not the array functions
V20 project with BlockArrays configured Documented whole-array support for this type Verify the configured type and its read behavior, then use it

Record the runtime version, target device, configured array type, element type and index bounds for each project, so the access scope is defined rather than guessed from the TIA Portal version.

How do you read a single array element from a V19 script? #

You put the index inside the tag name string, because the index belongs to the HMI address, not to a JavaScript subscript applied after the read:

// Read the configured HMI element at index 2.
let arrElement = Tags("ArrayVariable[2]").Read();

For a variable index, build that tag-name string before calling Read, for example with a loop counter i producing the address ArrayVariable[i]. Use the bounds shown in the tag configuration as your loop limits; deriving bounds from a parent-array read recreates the original failure. A local collection's first storage position and the HMI array's configured first index are separate decisions, so map them explicitly, and reject an out-of-range index in the script before the read is attempted.

How do you read the whole array when V19 only supports elements? #

You loop over the configured bounds, read each addressed element, and store the results in a local array that you own. For a ten-element array configured at indices 0 through 9, the loop performs 10 element reads: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and the local array ends with length 10 only if all 10 reads succeed, so count the successes and compare against 10 before using the copy.

Two limits follow from this. First, the local array is a snapshot in script memory: later PLC or HMI changes do not update it, so refresh the copy when the application needs current data. Second, the 10 reads happen at 10 different moments. For external tags connected to a PLC, a changing source can leave the local collection holding values from different updates. Where a coherent set matters, hold or coordinate the source in the PLC for the acquisition interval, or read a source that stays stable. The same sequential-read issue affects any script that samples the PLC over time, which is why an HMI script counting PLC bit changes needs timestamped intermediate observations rather than one late read.

How do you write all array elements at once? #

Build a TagSet: it transfers all elements in one operation, written simultaneously, with better performance and lower communication load than individual element writes. The documented example copies all elements of newSettings into currentSettings through a TagSet, replacing the element-by-element loop variant. Reading back the result afterwards is the acceptance test: every destination element must equal its source element after the write.

Prepare the mapping before writing. Equal array sizes alone do not establish which source element supplies which destination element; check bounds, element data types and the machine's permitted values first, and stop the transfer on an invalid source value rather than writing a partial set.

What breaks if you copy an external array element by element? #

Data inconsistency. The vendor's own note on the loop-based copy says that with external tags, elements written at different times can leave the destination array inconsistent if the PLC reads it mid-transfer, which is exactly why the TagSet variant exists: it writes the values consistently in one transfer. A settings copy into a live PLC array is the classic case; the loop variant is acceptable only where nothing consumes the destination until every write has finished.

How do you test array access before deploying the script? #

On an isolated bench, with a known tag name and verified test values. The sequence that separates the failure modes:

  1. Confirm the tag name ArrayVariable and that index 2 exists in the tag configuration.
  2. Give element 2 a distinguishable test value by an authorized method, read Tags("ArrayVariable[2]") and check the script returns that element, not an adjacent one.
  3. Read the lowest and highest configured indices with the same addressing rule, and confirm the script rejects an out-of-range index before reading.
  4. Run the full loop while the source holds stable values; every local element must match its HMI member, and the local length must equal the number of successful reads.
  5. For the TagSet write, verify all destination elements equal the sources immediately after the write, and that no consumer saw a partial set.
  6. Change a source value after acquisition and confirm the local copy stays unchanged until the script reads again.

Do you upgrade to V20 or rework the V19 script? #

Rework the V19 script with element reads and a TagSet write; that code runs unchanged on V19 today and still works on V20. Upgrade the project to V20 and configure BlockArrays only when the application genuinely needs documented whole-array reads of that specific tag type, and verify the configured type and its read behavior against the scripting documentation for your exact runtime build before moving the code over. For a deployment that must run on both versions, element reads are the common denominator.

Questions asked

Does upgrading from V19 to V20 make every HMI array readable as one JavaScript object?

No. V20 adds official whole-array support for tags configured as BlockArrays, a specific tag type that treats the array as a single data block. Ordinary scalar arrays keep the element-addressed access pattern, so a script written with element reads remains the portable choice across both versions.

Why did a whole-array read seem to work in one of my V19 projects?

Some V19 configurations return a usable result for a parent-array read, but that behavior is undocumented and configuration dependent, and updates were still planned to extend coverage. A script that relies on it can break on another device or after an update, so treat element reads as the supported path.

Can I get the array bounds from the tag at runtime instead of hard-coding them?

The element-read path gives no bounds, because you address the tag name yourself. Take the lower and upper index from the tag configuration in the engineering tool and put them in the loop limits. If a future whole-array API exposes bounds, verify it in the scripting documentation for your exact runtime version before relying on it.

Does the local JavaScript array stay live after I build it from element reads?

No. It is a copy in script memory. Later PLC or HMI changes do not alter values already read, and sequential reads can straddle different PLC updates. Refresh the copy when current data is needed, and coordinate with the PLC program if the source set must be coherent.

Keep reading

  • Troubleshooting

    Why WinCC Unified Scripts Cannot Launch a Batch File

    The WinCC Unified runtime's JavaScript API has no documented function that starts an external program, so SystemFunctions.launch fails on every path, escaping and wrapper you try. Do the PDF select, rename and copy with the runtime's Node.js fs module, or trigger a host-side service from a tag and keep execution outside the HMI.

    HMI and touchscreens

  • Troubleshooting

    Why a Linux Docker container cannot open the WinCC Unified PC OpenPipe

    WinCC Unified PC Runtime exposes OpenPipe as a Windows named pipe, and a Linux Docker container has no path to it: changing backslashes to slashes does not turn \\.\pipe\HmiRuntime into a Linux pathname. Use a Windows container, or put a bridge that exposes an OpenPipe-compatible Linux-side endpoint, and test mount errors and connection refusals separately.

    HMI and touchscreens

  • Explainer

    Why a WinCC Unified Faceplate Interface Has No Static Value Choice

    The WinCC Unified faceplate interface offers no static-versus-tag choice: the field takes a tag connection. Pass your constant through a WString or ULInt interface property and apply it in a script on the faceplate's Loaded event, or hold the constants as tags in a PLC data-block array and pass the selected tag.

    HMI and touchscreens

Why a WinCC Advanced SQL Read Script Returns Nothing