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

SOLVED
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 ?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Hi @iguerra.   Per the case that was opened, the issue wa...

Hi @iguerra.

 

Per the case that was opened, the issue was resolved after adding visibility permission to the Timer Things the thing template was dependent on.

 

If you are in agreement that this was the solution, please mark this response as the Accepted Solution for the benefit of others experiencing similar issues.

 

Regards.

 

--Sharon

View solution in original post

11 REPLIES 11
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)

Highlighted

Re: Permissions to create things pragmatically

Hi,

 

Try this. Go to EntityServices  > Permission >  Run time permission > Search "Create Thing" under property, service or event override section > select it. and search user or group name > select the service execute icon.
Find above steps in attached file.

 

Regards

Shyam

Highlighted

Re: Permissions to create things pragmatically

A part of the good comments that for sure Constantine had given.

 

On thing creation follow what this article https://www.ptc.com/en/support/article/CS198580 states about removing the thing on the catch if something fails to prevent Ghost entities on your instance.

 

Regards,

Carles.

Tags (1)
Highlighted

Re: Permissions to create things pragmatically

Hi @iguerra.

 

If you are still having issues, I recommend we open a case.  With your approval, I will be happy to open one on your behalf.

 

Regards.

 

--Sharon

Highlighted

Re: Permissions to create things pragmatically

Hi @iguerra.

 

Have you found a solution to your issue?  If so, please share it with the rest of the community.

 

Thank you for your participation!

 

Regards.

 

--Sharon

Highlighted

Re: Permissions to create things pragmatically

Hello

sorry but I missed notifications on this thread

I didn't find a solution (except giving visibility on all the collection instead of the template)

 

I already have the permission for visibility on EntityServices, and also RuntimePermission that allows System user to run services

So, there seems to be no problems on EntityServices

 

I also managed the deletion of ghost entities, in fact by reading documentation, I discovered that there where many ghost entities ... all those created with an error.

 

I opened a case.

Thanks

Highlighted

Hi @iguerra.   Per the case that was opened, the issue wa...

Hi @iguerra.

 

Per the case that was opened, the issue was resolved after adding visibility permission to the Timer Things the thing template was dependent on.

 

If you are in agreement that this was the solution, please mark this response as the Accepted Solution for the benefit of others experiencing similar issues.

 

Regards.

 

--Sharon

View solution in original post

Announcements

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