Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
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 ?
Solved! Go to Solution.
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
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
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
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 |
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)
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.
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
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
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
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