Skip to main content
1-Visitor
February 28, 2018
Solved

Add row in DataTable

  • February 28, 2018
  • 4 replies
  • 6344 views

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!

Best answer by AnselmoSilSaito

I found what I wanted...that's what I am talking about!

https://community.ptc.com/t5/ThingWorx-Developers/To-generate-dynamic-values-infotable-while-inserting-updating/m-p/530617

4 replies

22-Sapphire I
February 28, 2018

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)
1-Visitor
March 1, 2018

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.

22-Sapphire I
March 1, 2018

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.