Skip to main content
1-Visitor
January 17, 2019
Solved

Calling Thingworx Service Using Java Extension SDK

  • January 17, 2019
  • 2 replies
  • 3182 views

Hi,

 

I have a custom service on a Database Thing. I want to call that custom service from my Java Extension. My first thought is to do something like this

 

Thing myDB = ThingUtilities.findThing("MyDataBase");

InfoTable result = myDB.customService();

 

Is this the correct way?

 

Thanks,

Brandon

Best answer by bwinslow24

@slangley ,

 

None of these solutions were correct. The way I was able to get it working was with this code:

 

Thing db = ThingUtilities.findThing("dbThing");

InfoTable result = db.processServiceRequest("customService", null);

2 replies

5-Regular Member
January 23, 2019

Hi, Brandon.

 

One thing you might want to consider is adding some exception handling to the call to the Service.

 

See this article for some discussion and techniques for doing that.

 

Thanks,

-- Craig A.

5-Regular Member
January 23, 2019

If you want to search for your thing and then execute the service .You should find the thing like 

Thing mything =(Thing)EntityUtilities.findEntity("MyDBThing",ThingworxRelationshipTypes.Thing);

 

So the MyDBThing is the thing in composer and then you can proceed with the call of service keeping the return type in mind like mything.myservice();

 

For better design you should place this in try catch block .

 

Thanks ,

Mukul Narang 

Community Manager
February 1, 2019

Hi @bwinslow24.

 

If one of the previous responses answered your question, please mark the appropriate one as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

bwinslow241-VisitorAuthorAnswer
1-Visitor
February 4, 2019

@slangley ,

 

None of these solutions were correct. The way I was able to get it working was with this code:

 

Thing db = ThingUtilities.findThing("dbThing");

InfoTable result = db.processServiceRequest("customService", null);