2 Replies Latest reply on Oct 24, 2016 10:34 AM by sebastienl RSS
    sebastienl Explorer

    Issue when creating a Thing from an extention

    Hi,

     

    I'm creating an extension (TW 6.6.2) with a thread running as a "daemon" (the code will not be called by an authenticated user via the composer or a mashup). Based on some business logic this thread have to call a JavaScript service on a specific Thing. Because our code is not called with an authenticated context we are using this API before getting the Thing (switch to SuperUser):

     

    SecurityContext overrideContext = SecurityContext.createSuperUserContext();
    ThreadLocalContext.setSecurityContext(overrideContext);
    

     

    Then we get the Thing "processD" :

     

    Thing processD = (Thing) EntityUtilities.findEntity("processD", ThingworxRelationshipTypes.Thing);
    

     

    And then we call the Javascript service "process" :

     

    processD.processServiceRequest("process", params);
    

     

    If in the JavaScript service "process" we log messages or update Things it's working fine. But if we try to create a new Thing (let say '123')  we get this error :

     

    Execution error in service script [processD process] : Wrapped java.lang.Exception: Unable to create thing: 123 : null Cause: Unable to create thing: 123 : null

     

    Does anybody have an idea ? We are on this issue since several days, trying to make it works....

    Thanks a lot,

     

     

    EDITED1 : When executing this on PostgreSQL there is more info in error message :

     

    Execution error in service script [processD process] : Wrapped java.lang.Exception: Unable to create thing: 123 : [1 018] Data store unknown error: [Error occurred while accessing the model provider.] Cause: Unable to create thing: 123 : [1 018] Data store unknown error: [Error occurred while accessing the model provider.]

     

     

             Seb