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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Find thing by Name from .NET SDK

AlessandroN
12-Amethyst

Find thing by Name from .NET SDK

Hi all, I'm trying to check if a thing exists before do other stuff.
Actually I'm taking the "long road", invoking the  SearchThingsByTemplate service, but it doesn't work as well, since seems that the "thingTemplate" is not accepted as String.

(you can find the error log as attacched)

 

ValueCollection thingParams = new ValueCollection();
thingParams.Add("maxItems", new NumberPrimitive(500));
thingParams.Add("thingTemplate", new StringPrimitive(thingTemplate));
            
var infotable = client.invokeService(ThingworxEntityTypes.Resources, ,"SearchFunctions", "SearchThingsByTemplate", thingParams, 5000);

 

QUESTIONS:

 

- How can i give a "ThingTemplate" to this service?
- Can I check if a Thing exists in an other way?

 

Thanks in advance!

 

ACCEPTED SOLUTION

Accepted Solutions
slangley
23-Emerald II
(To:AlessandroN)

Hi @AlessandroN.

 

Unfortunately, the log file did not come through, but there is an example included in the .NET SDK download that may provide some guidance around your use case.  This example provides some alternative options to the approach you're using but may be helpful in determining the best design.  This page from the ThingWorx Help Center may also be helpful.

 

For the Thing Template name, you would need to provide that at the time the Thing is created.  You can find more information here.  Here is an article that may also help.  Here is an example for creating a Thing:

 

ValueCollection param = new ValueCollection();
_client.invokeService(com.thingworx.relationships.RelationshipTypes.ThingworxEntityTypes.Resources, "EntityServices", "CreateThing", param, 1000);

 

The example above does not spell out all the parameters available for creating a Thing, but the parameters available are the same ones you would see in Composer when creating a Thing manually.

 

Would recommend implementing some try/catch logic to determine if the Thing exists, checking the error (if it already exists), and then adding the logic needed for the desired outcome.

 

Regards.

 

--Sharon

View solution in original post

2 REPLIES 2
slangley
23-Emerald II
(To:AlessandroN)

Hi @AlessandroN.

 

Unfortunately, the log file did not come through, but there is an example included in the .NET SDK download that may provide some guidance around your use case.  This example provides some alternative options to the approach you're using but may be helpful in determining the best design.  This page from the ThingWorx Help Center may also be helpful.

 

For the Thing Template name, you would need to provide that at the time the Thing is created.  You can find more information here.  Here is an article that may also help.  Here is an example for creating a Thing:

 

ValueCollection param = new ValueCollection();
_client.invokeService(com.thingworx.relationships.RelationshipTypes.ThingworxEntityTypes.Resources, "EntityServices", "CreateThing", param, 1000);

 

The example above does not spell out all the parameters available for creating a Thing, but the parameters available are the same ones you would see in Composer when creating a Thing manually.

 

Would recommend implementing some try/catch logic to determine if the Thing exists, checking the error (if it already exists), and then adding the logic needed for the desired outcome.

 

Regards.

 

--Sharon

slangley
23-Emerald II
(To:AlessandroN)

Hi @AlessandroN.

 

If the previous response answered your questions, please mark it as the Accepted Solution for the benefit of others with the same questions.

 

Regards.

 

--Sharon

Announcements


Top Tags