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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

How to retrieve name of a thing by specifying ID and accessing its properties

tlichtenberger-
1-Visitor

How to retrieve name of a thing by specifying ID and accessing its properties

Good morning!

I have created  a few Things which inherit the properties from a ThingTemplate which holds a property Identifier string and another property for temperature.

In addition, I have created a helper thing to create a static service. This service gets two inputs: an identifier string and the temperature.

The service should retrieve the name of the thing which holds the same identifier string and should update the temperature property.

I have already found a function which seems to be made for that. It is called GetThingNameForIdentifier(identifier) and returns a THINGNAME.

But I haven't found anything on the internet on how to use this datatype and how to access the thing's properties.

Any suggestions?

Thank you in advance for your help

Theresa~

ACCEPTED SOLUTION

Accepted Solutions

Hi Theresa Lichtenberger

Please try:

Things[THINGNAME].temperature= temperature;

View solution in original post

8 REPLIES 8

Hi Theresa Lichtenberger

Please try:

Things[THINGNAME].temperature= temperature;

hi Ankit Gupta​,

and how do I use the GetThingnameByIdentifier(identifier) function?

Is it like this or am I doing anything wrong:


var params = {
identifier: ID/* STRING: ID is the property Name of the Thing */
};

// result: THINGNAME
var thingname = Resources["EntityServices"].GetThingNameForIdentifier(params);

Things[thingname].temperature= temperature;

thank you again for your help!

because if I test my service I get a the following error:

TypeError: Cannot set property "temperature" of null to "40"

Are you entering the identifier name in ID input? i.e. TestName for below example

thank you!

I now have defined identifiers. I first thought to take the self-defined identifier property of the thing (is this even possible?).

Hi Theresa Lichtenberger​,

There is no built-in service to find the Thing based on the custom property values.

We will have to create our custom service for that.

There could be a better way; here is what I would try:

1. Get list of all entities of type Thing.

2. Loop through the Things and get property Definition to find out which thing has my custom property.

3. If the Thing has the Custom Property; compare its value.

The service can be improved if we have more specific details about the Thing.

I hope it helps.

Theresa Lichtenberger​,

The service is correct. It works fine for me.

Please recheck that you are entering correct identifier for the Thing in input ID.

supandey
19-Tanzanite
(To:ankigupta)

Adding to what Ankit already said, you can check the default BaseTypes for ThingWorx via the API Documentation

Announcements


Top Tags