Skip to main content
1-Visitor
July 25, 2024
Solved

How to get data from an infotable and separate them into properties

  • July 25, 2024
  • 1 reply
  • 1381 views

Hello, 
I am using ThingWorx 9.3.9.
I was wondering if there was a method to get data from a infotable, and separate each of the columns in an property. In my case, I have three columns, id, temperature, and force, and I want to separate these into three different properties in a Thing. 

I have written a service in a Thing that has 4 properties, 3 of which are numbers and the last one being an infotable. 
This is my service code that I tried to use to pull one row of information from the infotable:

 

let infoTable = me.MyCSVProperty;
let searchCriteria = { 
	"id" : 2
};

let foundRow = infoTable.Find(searchCriteria);

if (foundRow!== null) {
 let id = foundRow.getValue(0);
 if (id!== null && id!== undefined) {
 me.id = id;
 } else {
 me.id = -1; // Set to -1 to indicate an error
 }
} else {
	me.id = 4;
}

 

and when i run this program i get an error:

AV_11504623_0-1721943807498.png

Any help would be greatly appreciated!
Additionally, I am new to coding and thingworx so detailed explanations would be great!

Thanks 

Best answer by Velkumar

Hi @AV_11504623 

 

Please use below code to update first row values.

 

 

let infoTable = me.MyCSVProperty;
let searchCriteria = {
id = 2;
}
let foundRow = infoTable.Find(searchCriteria);
if(foundRow !== null)
{
// Update property values
me.id = foundRow.id;
me.thermocouple = foundRow.thermocouple;
me.force= foundRow.force;
}

 

/VR

 

1 reply

Velkumar19-TanzaniteAnswer
19-Tanzanite
July 26, 2024

Hi @AV_11504623 

 

Please use below code to update first row values.

 

 

let infoTable = me.MyCSVProperty;
let searchCriteria = {
id = 2;
}
let foundRow = infoTable.Find(searchCriteria);
if(foundRow !== null)
{
// Update property values
me.id = foundRow.id;
me.thermocouple = foundRow.thermocouple;
me.force= foundRow.force;
}

 

/VR

 

4-Participant
July 27, 2024

It worked! Thank you so much!