cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Accessing Thing from Service

kylebur
1-Newbie

Accessing Thing from Service

I have a service that is making a REST API call to our platform, and then generates a bunch of Things with the response data. My current setup is to call the service from a Thing Template. My problem is that after creating the Things I need to add custom property definitions, which I can't always anticipate ahead of time. I don't see a "target existing Thing" snippet anywhere; is there a way I can add properties to the Things after they've been created, from the Template's service?

4 REPLIES 4

Hi Kyle,

You will need to access the AddPropertyDefinition service of the Thing you created.
You can refer to the thing you just created by simply saying Things["ThingName"].ServiceName(params)
The params for AddPropertyDefinition you can find by accessing Entities tab (from Service definition window) and then adding this method from an existing Thing.

Note: I didn't try, but you might need to restart the thing afterwards in order to make the property available for READ/WRITE from other services.

Hope it helps,
Vladimir



I see! Okay, I can now add properties to the things from the service.

I'm still not certain how to initialize the property after I've created it. The AddPropertyDefinition service doesn't seem to have a parameter for the value of the property (all properties will be persistent). Is there another service I need to call?

As for any Thing Property, for the setting the value of the property you can simply call Things["ThingName"].PropertyName = yourValue

Just as a side idea I think it would be a great help to check the very helpful videos on the Suport/Video tutorials tab (I know they helped me a lot!). There is a trick there, the videos you see when entering the Video Tutorial page are only a small subset from the available videos. To display them all, delete ThingWorx from the Search box, then press Search. Now wait some seconds (5-10) and you will see that the right video list scrollbar becomes very small and you will be able to scroll through a much, much larger Videos collection.

BR, Vladi

Vladimir,

I've run into some trouble trying to initialize Thing Properties. In the same service that I create the Thing, I use your recommended object notation to assign a value to the Thing's property. However, after the service is run, I check the Thing's properties manually to find they're blank. You mentioned in your first reply that I might need to "restart the thing." what did you mean by this?

Top Tags