Skip to main content
17-Peridot
January 15, 2024
Solved

Getting the value from QueryNamedPropertyHistory

  • January 15, 2024
  • 1 reply
  • 779 views

Hello Community,

 

I just got stuck on an issue and was hoping that perhaps someone here could help me.

I am using the QueryNamedPropertyHistory function for a property.

 

Getting this data, I want to loop it over and use each value for something.

 

Now, the issue I am facing is that the infotable data shape being used for the QueryNamedPropertyHistory is "dynamic".

 

It has the "timestamp" column and then the value column with is named after the property.

This makes it so I cant just do:

 

const propertyValues = Things[EntityName].QueryNamedPropertyHistory({
 ***params***
 });

 propertyValues.rows.toArray().forEach((element) => {
 let propertyValue = element.value;
 let propertyTimestamp = element.timestamp;
 });

 

As the "value" column changes name based on the property name.

 

I know you can do something like: 

Things[DynamicThing][DynamicProperty]

 

But is something similar possible in my use case?

Or how would you go about it?

 

Thanks,

Jens C.

Best answer by jensc

Hello Community,

 

I got some help from a colleague and they said it is possible to do:

element[PropertyName]

To get the value of the JSON key.

I should've known how to use this square bracket notation!

 

Thanks,

Jens C.

1 reply

jensc17-PeridotAuthorAnswer
17-Peridot
January 15, 2024

Hello Community,

 

I got some help from a colleague and they said it is possible to do:

element[PropertyName]

To get the value of the JSON key.

I should've known how to use this square bracket notation!

 

Thanks,

Jens C.