Skip to main content
1-Visitor
September 9, 2020
Solved

Unable to create Thing via Java Extension

  • September 9, 2020
  • 10 replies
  • 3162 views

Dear experts,

 

I am trying to create a Thing from a Service developed in an extension. I could easily do it in another extension by using: 

 

 

es.CreateThing(thingName, null, null, thingTemplateName);

 

 

Where es is an instance of EntityServices. I am developing another extension now and for some reason it always throws an Exception, saying that the ThingTemplate does not exist. The template is defined into the Extension itself and it is correctly seen by the composer. Moreover, instantiating a Thing from that Template from the Composer works.

 

Thanks and Best Regards 

Best answer by Raccone

Hi Vladmir,

 

I have identified the error. The point is that I think I was breaking the transaction internal to ThingWorx, as in the next row I was assigning the newly created Thing itself in the try block:

 

es.CreateThing(thingName, null, null, thingTemplateName);
userThing = ThingUtilities.findThing(thingName);

 

At least this is my explanation, and the only difference with the working pieces of code that I mentioned previously.  

10 replies

19-Tanzanite
September 9, 2020
Low chance this may be a Visibility issue created by the User you're using to execute the Service?
Raccone1-VisitorAuthor
1-Visitor
September 9, 2020

Hi Vladmir,

 

It got even creepier after that, when I created a new extension with a simple service that created a Thing, and it worked, on the Template I was referencing in the post before and also others.

 

Could the previous extension be corrupted or something like that?

19-Tanzanite
September 9, 2020
Hmm, I would not bet on the corruption. Maybe it's a crazy thing like the fact you passed an empty space in your templateName, or something like that. It happens a lot when you copy from Composer entity names. I always to do a trim for this reason. Other thing to keep in mind, if you have the chance, please connect your instance via JDWP to Eclipse so you can do proper debugging. Hard to do if the instance is not yours, but if you can, it's a life savior, especially seeing you're in the Extension teritory.
Support
September 24, 2020

Hi @Raccone.

 

If one of the previous posts allowed you to find a solution, please mark the appropriate one as the Accepted Solution for the benefit of others in the community.

 

Regards.

 

--Sharon

Raccone1-VisitorAuthor
1-Visitor
September 24, 2020

I forgot, I fixed it now.

 

Thanks,

Federico