Skip to main content
1-Visitor
August 13, 2014
Question

Accessing Thing from Service

  • August 13, 2014
  • 1 reply
  • 2262 views

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?

    1 reply

    19-Tanzanite
    August 14, 2014

    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



    kylebur1-VisitorAuthor
    1-Visitor
    August 14, 2014

    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?

    19-Tanzanite
    August 15, 2014

    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