InfoTable example in ThingWorx documentation (NativeObject cannot be cast to value collection)
Hi everyone,
While experimenting with InfoTables inside a ThingWorx service, I ran into some confusion regarding a documentation example that seems to contradict actual platform behavior. I’d like to get clarification (and maybe spark some discussion) around this.
Documentation Example
In the documentation , I found the following pattern:
var referencedInfoTable = Things["thingName"].myInfoTable;
var tableLength = referencedInfoTable.rows.length;
for (let i = 0; i < tableLength; i++) {
referencedInfoTable.rows[i] = {
field1: i,
field2: i * 2,
field3: i * 3
};
}
Things["thingName"].myInfoTable = referencedInfoTable;
// Comment from docs:
// "Because you are not using .AddRow() it doesn't require access to the referenced object's .AddRow() method,
// therefore it doesn't need to access the cache."
The Problem
When this code runs in ThingWorx (especially versions 9+ and 10+), it throws:
From what I understand, this happens because each rows[i] is a ThingWorx ValueCollection, and replacing it directly with a plain JavaScript object (NativeObject) breaks the expected Java type when saving back to a Thing property.
Working Version
Here’s the corrected version that works safely in all cases:
var referencedInfoTable = Things["thingName"].myInfoTable.clone();
var tableLength = referencedInfoTable.rows.length;
for (let i = 0; i < tableLength; i++) {
referencedInfoTable.rows[i].field1 = i;
referencedInfoTable.rows[i].field2 = i * 2;
referencedInfoTable.rows[i].field3 = i * 3;
}
Things["thingName"].myInfoTable = referencedInfoTable;
This avoids replacing the ValueCollection and simply modifies its internal fields — no casting errors, and it persists correctly.
My Question
Why does the documentation show replacing the entire row object instead of updating the existing ValueCollection fields?
Was that example intended:
-
only for in-memory testing (without writing back to a Thing property)?
-
or is there some other underlying purpose (e.g., caching demonstration)?
Would love to hear your insights or any official clarification from PTC on this one.
Thanks in advance for helping me (and probably a lot of others) understand the intended usage pattern here!

