Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
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!
Solved! Go to Solution.
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
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
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