Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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!
Solved! Go to Solution.
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
I think this could help, you should be able to iterate through the Fields I think and get the names of the Fields.
---------------------------
// 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);
}
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.
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