<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: InfoTable example in ThingWorx documentation (NativeObject cannot be cast to value collection) in ThingWorx Developers</title>
    <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1044084#M70951</link>
    <description>&lt;P&gt;Hi &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/709891"&gt;@MA8731174&lt;/a&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears that you have found the answer to your question. &amp;nbsp;For the benefit of other Community Members who may have the same question, it would be helpful if you could designate the appropriate response as the Accepted Solution.&lt;BR /&gt;&lt;BR /&gt;Thanks for using the PTC Community!&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;--Sharon&lt;/P&gt;</description>
    <pubDate>Wed, 19 Nov 2025 19:43:55 GMT</pubDate>
    <dc:creator>slangley</dc:creator>
    <dc:date>2025-11-19T19:43:55Z</dc:date>
    <item>
      <title>InfoTable example in ThingWorx documentation (NativeObject cannot be cast to value collection)</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1042525#M70858</link>
      <description>&lt;P data-start="394" data-end="411"&gt;Hi everyone,&lt;/P&gt;
&lt;P data-start="413" data-end="664"&gt;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.&lt;/P&gt;
&lt;P data-start="413" data-end="664"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="671" data-end="703"&gt;&lt;STRONG data-start="678" data-end="703"&gt;Documentation Example&lt;/STRONG&gt;&lt;/H3&gt;
&lt;P data-start="705" data-end="792"&gt;In the documentation , I found the following pattern:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;var referencedInfoTable = Things["thingName"].myInfoTable;
var tableLength = referencedInfoTable.rows.length;

for (let i = 0; i &amp;lt; 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."
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="1303" data-end="1325"&gt;&lt;STRONG data-start="1310" data-end="1325"&gt;The Problem&lt;/STRONG&gt;&lt;/H3&gt;
&lt;P data-start="1327" data-end="1404"&gt;When this code runs in ThingWorx (especially versions 9+ and 10+), it throws:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"&gt;
&lt;DIV class="sticky top-9"&gt;
&lt;DIV class="absolute end-0 bottom-0 flex h-9 items-center pe-2"&gt;
&lt;DIV class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="overflow-y-auto p-4" dir="ltr"&gt;&lt;CODE class="whitespace-pre!"&gt;&lt;SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;class&lt;/SPAN&gt; org.mozilla.javascript.NativeObject cannot be &lt;SPAN class="hljs-keyword"&gt;cast&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;to&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;class&lt;/SPAN&gt; com.thingworx.&lt;SPAN class="hljs-keyword"&gt;types&lt;/SPAN&gt;.collections.ValueCollection
&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE class="overflow-visible!" data-start="1406" data-end="1527"&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P data-start="1529" data-end="1764"&gt;From what I understand, this happens because each &lt;CODE data-start="1579" data-end="1588"&gt;rows[i]&lt;/CODE&gt; is a ThingWorx &lt;CODE data-start="1604" data-end="1621"&gt;ValueCollection&lt;/CODE&gt;, and replacing it directly with a plain JavaScript object (&lt;CODE data-start="1681" data-end="1695"&gt;NativeObject&lt;/CODE&gt;) breaks the expected Java type when saving back to a Thing property.&lt;/P&gt;
&lt;HR data-start="1766" data-end="1769" /&gt;
&lt;H3 data-start="1771" data-end="1796"&gt;&lt;STRONG data-start="1777" data-end="1796"&gt;Working Version&lt;/STRONG&gt;&lt;/H3&gt;
&lt;P data-start="1798" data-end="1858"&gt;Here’s the corrected version that works safely in all cases:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;var referencedInfoTable = Things["thingName"].myInfoTable.clone();
var tableLength = referencedInfoTable.rows.length;

for (let i = 0; i &amp;lt; tableLength; i++) {
    referencedInfoTable.rows[i].field1 = i;
    referencedInfoTable.rows[i].field2 = i * 2;
    referencedInfoTable.rows[i].field3 = i * 3;
}

Things["thingName"].myInfoTable = referencedInfoTable;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="2228" data-end="2359"&gt;This avoids replacing the &lt;CODE data-start="2254" data-end="2271"&gt;ValueCollection&lt;/CODE&gt; and simply modifies its internal fields — no casting errors, and it persists correctly.&lt;/P&gt;
&lt;P data-start="2228" data-end="2359"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="2366" data-end="2388"&gt;&lt;STRONG data-start="2373" data-end="2388"&gt;My Question&lt;/STRONG&gt;&lt;/H3&gt;
&lt;P data-start="2390" data-end="2540"&gt;Why does the documentation show replacing the entire row object instead of updating the existing &lt;CODE data-start="2515" data-end="2532"&gt;ValueCollection&lt;/CODE&gt; fields?&lt;/P&gt;
&lt;P data-start="2542" data-end="2568"&gt;Was that example intended:&lt;/P&gt;
&lt;UL data-start="2569" data-end="2812"&gt;
&lt;LI data-start="2569" data-end="2647"&gt;
&lt;P data-start="2571" data-end="2647"&gt;only for &lt;STRONG data-start="2580" data-end="2601"&gt;in-memory testing&lt;/STRONG&gt; (without writing back to a Thing property)?&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-start="2738" data-end="2812"&gt;
&lt;P data-start="2740" data-end="2812"&gt;or is there some other underlying purpose (e.g., caching demonstration)?&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Would love to hear your insights or any official clarification from PTC on this one.&lt;BR data-start="3152" data-end="3155" /&gt;Thanks in advance for helping me (and probably a lot of others) understand the intended usage pattern here!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Nov 2025 09:33:53 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1042525#M70858</guid>
      <dc:creator>MA8731174</dc:creator>
      <dc:date>2025-11-09T09:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: InfoTable example in ThingWorx documentation (NativeObject cannot be cast to value collection)</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1042564#M70860</link>
      <description>&lt;P&gt;The code block you are quoting is introduced with the following text: "Avoid manipulating Thing properties directly as this can result in persistent synchronization issues and loss of performance." The point is to not access the infotable row props if the infotable is a thing property because each update has to go through the cache. Instead, take an "offline" infotable (i.e not being a thing property) and update that all you want, and then write it back once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you reference is the third example in that section, labelled as "for your information", with the point being mentioned in the comment, to not access through the methods. That it's not working is probably an oversight and you can report this with the top-right mail button to the doc team.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Nov 2025 07:13:53 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1042564#M70860</guid>
      <dc:creator>Rocko</dc:creator>
      <dc:date>2025-11-10T07:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: InfoTable example in ThingWorx documentation (NativeObject cannot be cast to value collection)</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1042570#M70862</link>
      <description>&lt;P&gt;Thanks for info&amp;nbsp;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/244971"&gt;@Rocko&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have undetstood now that this behavior happens because there’s an important difference between an&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;InfoTable Thing Property&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and an&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;InfoTable used as a service parameter or local variable&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;When you access an InfoTable that belongs to a Thing, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;var myInfo = Things["MyThing"].&lt;WBR /&gt;MyInfoTableProperty;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you’re actually working with a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;proxy object&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that is directly linked to the Thing’s property and its defined DataShape.&lt;BR /&gt;Because of that, ThingWorx already knows the field names and data types, so you can modify rows directly (e.g.,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;myInfo.rows[i] = {...}&lt;/CODE&gt;) and then assign it back:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Things["MyThing"].&lt;WBR /&gt;MyInfoTableProperty = myInfo;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works because the proxy handles the validation and synchronization for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when you use an&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;InfoTable as a service input or output parameter&lt;/STRONG&gt;, even if it uses the same DataShape, it’s not connected to any Thing property. It’s just a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;local runtime object&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in memory, not a proxy.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ThingWorx does not automatically apply DataShape validation to direct row assignments in this case, so code like this will fail:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;inputTable.rows[i] = { temperature: 25 };
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correct way to work with service InfoTables is to use the ThingWorx API methods:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;var newTable = Resources["InfoTableFunctions"&lt;WBR /&gt;].&lt;WBR /&gt;CreateInfoTableFromDataShape({
    infoTableName: "InfoTable",
    dataShapeName: "MyDataShape"
});

newTable.AddRow({ temperature: 25, pressure: 12 });
result = newTable;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or, if you just want to edit existing rows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;inputTable.rows.toArray().&lt;WBR /&gt;forEach(function(row) {
    row.temperature = 25;
});
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;In short:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;Thing property InfoTables =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;proxy objects&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;tied to a Thing → can be modified directly.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Service InfoTables =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;local copies&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;→ must use AddRow() or API methods to update&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 10 Nov 2025 07:46:12 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1042570#M70862</guid>
      <dc:creator>MA8731174</dc:creator>
      <dc:date>2025-11-10T07:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: InfoTable example in ThingWorx documentation (NativeObject cannot be cast to value collection)</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1044084#M70951</link>
      <description>&lt;P&gt;Hi &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/709891"&gt;@MA8731174&lt;/a&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears that you have found the answer to your question. &amp;nbsp;For the benefit of other Community Members who may have the same question, it would be helpful if you could designate the appropriate response as the Accepted Solution.&lt;BR /&gt;&lt;BR /&gt;Thanks for using the PTC Community!&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;--Sharon&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 19:43:55 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/InfoTable-example-in-ThingWorx-documentation-NativeObject-cannot/m-p/1044084#M70951</guid>
      <dc:creator>slangley</dc:creator>
      <dc:date>2025-11-19T19:43:55Z</dc:date>
    </item>
  </channel>
</rss>

