Skip to main content
1-Visitor
Feb 28, 2018 8:35 PM UTC
Solved

Add row in DataTable

Hi All,

I am creating a service that add row into a DataTable.
The problem is..I dont know my fields name.
So what I need is to iterate through  the fields and add the values I want.

Something like...
for(each field){

myDataTable.field.value = value[x];

x++;

}
But in "Thingworx language".

Any tips?

Thanks!

1-Visitor
Mar 1, 2018 3:54 PM UTC

4 replies

22-Sapphire I
Feb 28, 2018 9:22 PM UTC

I think this could help, you should be able to iterate through the Fields I think and get the names of the Fields.

 

http://support.ptc.com/cs/help/thingworx_hc/thingworx_7.0_hc/index.jspx?id=IteratingThroughaThingsProperties&action=show

 

---------------------------

Iterating Through a Thing's Properties
You can easily iterate through a Thing's properties and examine the properties using the following technique:
// GetPropertyValues(): returns an INFOTABLE

var values = me.GetPropertyValues();var field;

// Now we can iterate through the INFOTABLE FIELDS through the DataShape

for each(field in values.dataShape.fields) {

var propValue = values[field.name];

if(field.baseType == "NUMBER") logger.warn(field.name + " " + field.baseType + " " + propValue);

}
You can even access the aspects of an individual field. For example, when you create a property, there are additional aspects of the property that you can define. Use the following technique/pattern to examine the property's aspects:
  • field.aspects(isPersistent)
  • field.aspects(minimumValue)
Translate
1-Visitor
Mar 1, 2018 1:25 PM UTC

The function getProperty returns only generic fields of my datatable, but nothing about datashape.

 

 

var values = me.CreateValues();

values.a= undefined; //STRING
values.b= undefined;

 

What I want is: get my datashape fields and insert values...without using the code above but iterating.

Translate
22-Sapphire I
Mar 1, 2018 1:50 PM UTC

If you know which Property is your InfoTable then you can just iterate to get the fields.

for each (var field in infotable.fields)

I have some actual example lying around somewhere I could dig up, but this should work.

Translate