Skip to main content
1-Visitor
April 4, 2017
Solved

Extracting data from an infotable. Error: Unable To Convert From .ValueCollection to INFOTABLE.

  • April 4, 2017
  • 1 reply
  • 5352 views

Hi there, I'm trying to extract a row from the infotable as per the code below.

var table = me.myInfoTable;

var someRow = table.rows[0];

var result = someRow;

After executing the script I'm getting the following error (composer). Why is that? I'm pretty sure I could do it before.

The infotable is not empty. The data can be accessed by addressing field names.

var someName = someRow.someField;


The output is set to an infotable with the appropriate datashape.



Best answer by nkhose

You are not adding the row you got to infotable 

you should do as like

var params = {

  infoTableName : "InfoTable",

  dataShapeName : "testds"

};

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

var devices = Things["Remote"].GetDataTableEntryByKey({key:'uhii'});

var row = devices.getRow(0);

result.AddRow(row)

1 reply

nkhose1-VisitorAnswer
1-Visitor
April 4, 2017

You are not adding the row you got to infotable 

you should do as like

var params = {

  infoTableName : "InfoTable",

  dataShapeName : "testds"

};

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

var devices = Things["Remote"].GetDataTableEntryByKey({key:'uhii'});

var row = devices.getRow(0);

result.AddRow(row)

Michail1-VisitorAuthor
1-Visitor
April 5, 2017

Nilesh Khose, thank you! It worked.

Although I did not explicitly create a separate infotable using the functions provided, perhaps you could explain why I can access those fields as per the code below?

var someName = someRow.someField;

A method of accessing row fields (without creating a separate table and adding rows to it) is used quite broadly.

The question arises - what is a value collection in the context of ThingWorx? Thanks.

5-Regular Member
April 5, 2017

Hi mnudel​,

var someRow = table.rows[0];

Here someName is a value collection. In general it's an object or array of different type of elements.

We can refer to elements by <value_collection>.<field_name>.

It is to add a row to an infotable in ThingWorx or refer to an element/cell of an infotable.

I hope it helps.