Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hello,
I need to add couple of new properties to my Things at run-time. To achieve this I have tried using "AddPropertyDefinition" service from my composer environment. I am using ThingWorx 8.1.0. I sought references from various topics like -
https://www.ptc.com/en/support/article?n=CS233812
https://community.ptc.com/t5/ThingWorx-Developers/Thing-addProperty-doesn-t-work/m-p/527530#M21446
As mentioned in one of the links that it is needed to restart the Thing, I tried doing that, but doesn't work for me.
The execution of this service does not return any error, but does not give the expected output as well.
I tried to also use this service using "Test Service" button against the same service listed under generic services for a Thing.
Any possible reasons for the same?
Regards
Aditya Mittal
Solved! Go to Solution.
Why not a custom service? please do it with the custom service where you can do a thing Restart right on.
Can you share your code?
Hi Carles,
I am not doing it by any custom service, I am first trying to add the property using the "Test" service option (attached screen shot for reference) for a Thing (based on generic Thing template). I have filled in the required values like name, basetype and description. Service execution seems successful (as there is no exception or error). But still the property is not added in my thing.
Please let me know in case any other information is required from my end to better understand the issue.
Thanks
Aditya
Why not a custom service? please do it with the custom service where you can do a thing Restart right on.
Hello Carles,
YES..Its working now!!!. I did a custom service, and called re-start thing and the property was added. It worked.
Thanks a lot for your support and suggestion.
I will also assume that in case I need to add multiple properties, I will add them first all at once, using "AddPropertyDefinition", and then after adding the properties I need, I will do a restart thing once to have them all added my thing.
But it was surprising it did not work using the Test option, and I actually, as suggested, did a restart thing by enabling and disabling the thing and saving it. I thought that step is synonymous to restart thing (as thingStart event is fired after this step).
But anyways, restart thing service made it work. I'll accept it as solution.
Regards
Aditya
There's a big difference between Test on Composer and a Service as a whole --> The transaction, on the Service as a whole you do on the same transaction the Add Property and Restart, with Test on Composer you do different transactions ;)
Yes, to add multiple properties, first add them all an then restart.
Hello Carles,
Thanks for that. To understand some more, the provision for setting up remote binding option(s) in the service AddPropertyDefinition is similar to what is achieved by calling the service "SetRemotePropertyBinding", is that right? But we don't have a provision to do what is achieved by "SetLocalPropertyBinding".
So if I have to set local property binding, I have to add the properties to my thing, restart the thing and do the local property binding activity for those properties probably in the thingstart event subscription (as it would be fired, once the thing restarts after adding the properties) right..?
I definitely cannot do "SetLocalPropertyBinding", just after calling the custom service to create the properties, as the stack context would be lost after restart thing. Right??
I hope I am able to express, what I am trying to do, properly in writing. But please let me know if you need any further clarification.
Regards
Aditya
Just test it please.
Hello Carles,
If there are multiple properties to add to a thing, one option as we discussed in this post is to use the service "AddPropertyDefinition" in a loop, but I can see there is also a service "AddPropertyDefinitions". It accepts an Infotable and a bool type parameter, but I am not sure, what datashape that infotable shall be? Should that Infotable be of type 'PropertyDefination' datashape? I am not able to find required infomation/documnetation to use that service. Any help would be appreciated.
Regards
Aditya