cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Permissions to create things pragmatically

Highlighted
Amethyst

Permissions to create things pragmatically

Hello

I have a system user that needs to create pragmatically things based on template "MYTemplate"

 

I gave visibility and service exec permission to EntityServices->CreateThing

I gave permission to Create on "things collection"

the User has also visibility to all things based on MYTemplate (it is set visibility at template level)

 

That user can run the service CreateThing, no errors like serviceinvoke or not allowed to Create ... but I get the error JavaException: java.lang.NullPointerException: null at the CreateThing call.

NOTE that the thing was created however !

 

I solve only if I give to User the visibility permission to all the "things collection", seems the permission only on the template is not enough for creating things.

 

It seems like if for an instant the Service creates the thing, but he can't see it after all , because it still don't know that is based on the MYTemplate that instead makes it visible to that user.

 

Is the visibility to all things collection the only solution ?

 

 

 

5 REPLIES 5
Highlighted

Re: Permissions to create things pragmatically

Hello @iguerra,

 

The quick answer is "no, you don't need full visibility to create things".

 

It will be easier to find the issue if you provide the code, highlighting the line which throws a NullPointerException.

 

/ Constantine

Highlighted

Re: Permissions to create things pragmatically

here the code, error on CreateThing row

try {
	var MachineName ="Macchina_XXXX";

    if (Things[MachineName] == undefined) {

        var params = {
            name: MachineName /* STRING */,
            description: undefined /* STRING */,
            thingTemplateName: "MyTemplate" /* THINGTEMPLATENAME */,
            tags: undefined /* TAGS */
        };
        logger.info("Creating Thing [" + MachineName + "]");

        Resources["EntityServices"].CreateThing(params);   <--- ERROR HERE !!!!!!!!!!!!
        Things[MachineName].EnableThing();
        Things[MachineName].RestartThing();
    }
}
catch(e) {
    logger.error("testcreate error " + e + " on line " + e.lineNumber);
}

 

All works fine if the user who run is on administrators group, or if I just give visibility of things collection to such user

 

 

Highlighted

Re: Permissions to create things pragmatically

On applicatio Log I get on the same timestamp this error

2020-05-21 08:46:35.511  Error ErrorCode(91f6d227-8ee5-4811-8f16-05a4b9579ccb), Cause(null), Reason(Access was attempted on a null reference variable.), Possible Resolutions(Remove the reference to the null variable within your extension code.) System c.t.c.p.ReflectionProcessor TWEventProcessor-3
Highlighted

Re: Permissions to create things pragmatically

Does your user have visibility on the “EntityServices” resource?
Highlighted

Re: Permissions to create things pragmatically

yes, on Visibility and also in Service Execute (Run Time)

without those permission if would give "not found" error accessing Resources["EntityServices"] or "not allowed on service invoke " when calling Resources["EntityServices"].CreateThing(params)

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!