3 Replies Latest reply on Aug 6, 2014 11:36 AM by adam RSS
    mateuszboc Explorer

    JavaScript CreateThing - Thing is not running

    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 is not running Cause: Thing 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? 


      • JavaScript CreateThing - Thing is not running
        adam Creator

        Hi Mateusz,

         

        After programmatically creating a

        Thing

        (or any entity), you need to invoke two

        Services

        : (1)

        EnableThing()

        and (2)

        RestartThing()

        . Once you enable and restart the

        Thing

        , you are able to use it just as you would any

        Thing

         created manually in Composer.


        By the way, you'll want to make sure you are using proper error handling in

         

        the

        Service

         creating

        Things

        . For example, if your

        Service

         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



        • JavaScript CreateThing - Thing is not running
          mateuszboc Explorer

          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?