How to add property values of a thing to infotable in ThingWorx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
How to add property values of a thing to infotable in ThingWorx
Hello,
I want to add property values of a thing to an infotable/datatable thing in ThingWorx,
For Eg: I have a datatable with a datashape having three columns(column 1, column 2, column 3)
also, I have 3 properties (column1Prop, column2Prop, column3Prop)
I want to add these properties as a Row to the datatable.
Can anyone help me please.
Thanks in advance.
Regards,
Aditya Gupta
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi Aditya,
you would create a subscription to a DataChangeEvent that fires whenever one of those properties was changed.
in that subscription you would add a row to the dataTable. Roughly like this:
let v=DataShapes["TheDataShapeOfYourDataTable"].CreateValues();
v.AddRow({prop1:eventData.newValue.prop1, prop2:eventData.newValue.prop2, prop3:eventData.newValue.prop3);
me.AddDataTableEntry({values: v});
The question is though why you would not use Value Streams instead which are explicitly made for that use case. Just assign a value stream to the thing and set the three properties to "logged".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Surya_Tiwari ,
I am not able to understand this, I will just brief you once again what I want to achieve:
I have few properties which are changing, so everytime the value changes I want to add those property values into a datatable.
eg. I have property1, property2 & property3 so evertyime the value of these properties changes I want to record them into a datatable.
Do you have any solution for this?.
Thank You.
Regards,
Aditya Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi Aditya,
you would create a subscription to a DataChangeEvent that fires whenever one of those properties was changed.
in that subscription you would add a row to the dataTable. Roughly like this:
let v=DataShapes["TheDataShapeOfYourDataTable"].CreateValues();
v.AddRow({prop1:eventData.newValue.prop1, prop2:eventData.newValue.prop2, prop3:eventData.newValue.prop3);
me.AddDataTableEntry({values: v});
The question is though why you would not use Value Streams instead which are explicitly made for that use case. Just assign a value stream to the thing and set the three properties to "logged".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hello @Rocko ,
Thanks for your reply.
I am new to thingworx so, can you please provide me a step by step solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Sounds good. Please do not forget to plan purging the value stream regularly to not overfill your database. You can read about it in the help and here: https://www.ptc.com/en/support/article/CS271772
I also recommend the ThingWorx Learning Paths to get started with ThingWorx: https://community.ptc.com/t5/IoT-Tips/ThingWorx-Learning-Paths/ta-p/841623
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Rocko ,
Good Morning,
What if I want to move this stored data to some other database or any storage for my future reference
then how do I go about it?
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
One way of doing it is to create a JDBC connection to the other database. Then with a scheduler, query the data you want to move out, iterate over the returned infotable and insert the rows into the other database.
For reference:
https://community.ptc.com/t5/IoT-Tips/Working-with-External-Databases-Part-1/ta-p/833992
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Okay.
I will surely try & let you know if any issues.
Thank You.
Regards,
Aditya Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Rocko ,
Good Morning,
Value Stream did worked for me.
I set the properties to be logged & then executed QueryPropertyHistory Service.
Hope this is the right way.
Thanks & Regards,
Aditya Gupta
