Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Hi All,
How can i convert string to thing name or thing template name to access entity services within eclipse?
How can i define a thing template name as like Base Types?
Thanks.
Solved! Go to Solution.
Hi,
I posted above a general rule, so you can apply it to any use case.
Answering directly, you can do the following (please keep in mind, that I implemented this code on Extension SDK 8.0.0, on other SDK version it can be slightly different):
ThingTemplate genericTemplate = (ThingTemplate) EntityUtilities.findEntity(entityName, ThingworxRelationshipTypes.ThingTemplate); InfoTable implementingThings = genericTemplate.GetImplementingThings(); implementingThings.getRows().stream().forEach(row -> { Thing t = ThingUtilities.findThing(row.getStringValue("name")); _logger.warn("Thing based on GenericThing: " + t.getName()); });
Please also be aware, that the above code is just a snippet, example.
If you consider my answer correct, please mark it as such, so other can refer.
BR,
Jakub.
Hi @Sathishkumar_C,
In general, entity names are just a String from a back-end perspective. To reach Thing and its characteristics, you can do the following:
String entityName = "MyThing";
// there are various ...Utilities classes that will help to find a proper entity
Thing myThing = ThingUtilities.findThing(entityName);
// OOTB service
ThingProperty myProperty = myThing.getProperty("MyProperty");
// custom service
ValueCollection inputParams = new ValueCollection();
inputParams.SetStringValue("InputParam1", "In");
inputParams.SetNumberValue("InputParam2", 5);
InfoTable output = myThing.processServiceRequest("CustomService", inputParams);
Hope that it answers your question. If yes, please mark my answer as a correct one for other for the reference.
BR,
Jakub.
Thanks for your reply.
I want to return "GetImplementingThingWithData" for a particular thing template. How can i achieve this.?
Hi,
I posted above a general rule, so you can apply it to any use case.
Answering directly, you can do the following (please keep in mind, that I implemented this code on Extension SDK 8.0.0, on other SDK version it can be slightly different):
ThingTemplate genericTemplate = (ThingTemplate) EntityUtilities.findEntity(entityName, ThingworxRelationshipTypes.ThingTemplate); InfoTable implementingThings = genericTemplate.GetImplementingThings(); implementingThings.getRows().stream().forEach(row -> { Thing t = ThingUtilities.findThing(row.getStringValue("name")); _logger.warn("Thing based on GenericThing: " + t.getName()); });
Please also be aware, that the above code is just a snippet, example.
If you consider my answer correct, please mark it as such, so other can refer.
BR,
Jakub.
Look's good.