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,
I encounter problem when implementing service for creating Things based on my template.
Part of the script with changed strings:
var params = {
thingTemplateName: 'XXXTemplate' /* THINGTEMPLATENAME /,</div><div> description: 'description' / STRING /,</div><div> name: 'xxx-11' / STRING */
};
// no return
Resources["EntityServices"].CreateThing(params);
// no return
Things[newNodeName].EnableThing();
When I called another service via REST API I get an error:
Wrapped com.thingworx.common.exceptions.InvalidRequestException: Thing /xxx-11 is not running Cause: Thing /xxx-11 is not running
When I open this newly created Thing in Composer and save without changing anything - it works.
When I go to .../Thingworx/Things/xxx-11 it also exists. Webpage says it is enabled.
Where is the problem? How to run this new Thing?
Hi Mateusz,
After programmatically creating a
Thing
(or any entity), you need to invoke twoServices
: (1)EnableThing()
and (2)RestartThing()
. Once you enable and restart theThing
, you are able to use it just as you would anyThing
created manually in Composer.By the way, you'll want to make sure you are using proper error handling in
the
Service
creatingThings
. For example, if yourService
throws an exception before the entire transaction is committed to the database, you'll wind up with "ghost"Things
that can only be removed by restarting Tomcat.Regards,
Adam
Hi, Thanks. It works. I'm pretty sure I've tried RestartThing() yesterday...
What do you mean by proper error handling as this functions (Create/Enable/RestartThing) have no return? Some small example?
Mateusz,
You'll want to use try-catch blocks to handle exceptions. Typically, you'll wrap your entire
Service
in a try-catch, as uncaught exceptions from any code in yourService
will introduce "ghost"Things
that only exist in memory.