Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! 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.