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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Permissions to create things pragmatically

iguerra
14-Alexandrite

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
slangley
23-Emerald II
(To:slangley)

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

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

iguerra
14-Alexandrite
(To:Constantine)

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

 

 

iguerra
14-Alexandrite
(To:iguerra)

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

Does your user have visibility on the “EntityServices” resource?
iguerra
14-Alexandrite
(To:Constantine)

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)

BABA-SHYAM
14-Alexandrite
(To:iguerra)

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

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.

slangley
23-Emerald II
(To:iguerra)

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

slangley
23-Emerald II
(To:slangley)

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

iguerra
14-Alexandrite
(To:slangley)

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

slangley
23-Emerald II
(To:slangley)

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

Top Tags