cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Add row in DataTable

AnselmoSilSaito
12-Amethyst

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 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4

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)

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.

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.

Top Tags