Skip to main content
14-Alexandrite
March 5, 2021
Question

Modifying Entries in InfoTable / Behaviour changed with newer Thingworx

  • March 5, 2021
  • 1 reply
  • 7186 views

Hi all,

 

for some aggregation in memory I used an Infotable.

So my Thing has an property of type INFOTABLE and I can access the rows to read/write single entries. e.g:

var now = new Date();
me.tab.rows[0].ts_set = now;
var result = me.tab;

Thingworx 8.4 & 8.5 give me a result with the correct now() timestamp in the first row.

I now tested this code in Thingworx 9.1 and it does not give me the correct now() timestamp in the first row!

 

So is it not possible to modify single entries in INFOTABLES in place any more?
Do I really have to copy the INFOTABLE every time I access it and change the code to:

var now = new Date();
var tab = me.tab;
tab.rows[0].ts_set = now;
me.tab = tab;
var result = me.tab;

Any suggestion, please?

 

Greetings

 

Andreas

 

 

1 reply

atondorf14-AlexandriteAuthor
14-Alexandrite
March 5, 2021

I attached a small datashape and a thing to test this.

TestInfotableDS only contains two values: id (long), ts (Date).

The thing TestInfoTable has an infotable of this shape and one service addRow().

var tab = me.tab;
var count = tab.getRowCount(),
var entry = {
 id: count,
 ts: new Date()
};
tab.AddRow(entry);
if( count > 0 )
 tab.rows[count-1].id -= 1; // does not work in TWX 9.1
/* 
 * uncomment to make it work in TWX 9.1! 
 * But why does AddRow reflect back to property and in place mod not?
 */
// me.tab = tab; 
var result = me.tab;

As described in the Thingworx Help - Infotables the local variable tab reflects back to the property me.tab.

But each time a row is added to the infotable the id of the previous row should be decremented by one.

This happens in Thingworx 8.4 & 8.5 but not in THingworx 9.1.

 

Is this intended behaviour? How can I modify values in an infotable in place?

17-Peridot
March 5, 2021

@atondorf What do you mean as "does not give me the correct now() timestamp"?

 

I don't have 9.1 at hand atm, but I did a quick test on 9.0 and timestamps look good.

Is the behaviour / output in 9.0 correct / expected and the same as you observe on 8.4 / 8.5?

 

Unbenannt03.JPG

atondorf14-AlexandriteAuthor
14-Alexandrite
March 8, 2021

Hello Dmitry,

 

no that is exactly the not planned behaviour ...
To make it more clear I modified my code and extended the DataShape by a string value:

var tab = me.tab;
var count = tab.getRowCount();
var entry = {
	id: count,
 ts: new Date(),
 value: "Original" 
};
tab.AddRow(entry);
if( count > 0 ) { // if there is a prev row, modify it!
 tab.rows[count - 1].id -= 1; // does not work in TWX Version > 9.0
 tab.rows[count - 1].value = "Modified"; // does not work in TWX Version > 9.0
}
// me.tab = tab; 
var result = me.tab;

So when I execute this Service 3 times I get different results for TWX 8 & 9.

In Thingworx 8.x it's:

2021-03-08 07_43_32-Services _ TestInfoTable und 3 weitere Seiten - Geschäftlich – Microsoft​ Edge.png

 When I do the same in Thingworx 9.x:

2021-03-08 07_56_31-Services _ TestInfoTable und 3 weitere Seiten - Geschäftlich – Microsoft​ Edge.png

So it seems that in place modification of Infotables is not possible any more strating with THingworx 9.0!

That's horrible for many of our internal logics ...

If this is intended behaviour I would expect a huge exclamation mark in the Documentation. 

ATTENTION!! Behaviour of in place operations changed!