Hi
If have a strange issue with ReadPermission, NAV 2013R2.
This works
RecRef.OPEN(TableID);
If RecRef.READPERMISSION THEN…
This does not work (RunTimeError on first line of code, "Access is denied to Company <TheCompanyName>")
RecRef.OPEN(TableID,False,TheCompanyName);
If RecRef.READPERMISSION THEN…
So my problem is, code does not reach the line to test with ReadPermission, because the OPEN command fails.
Thanks in advance.
Thomas
0
Answers
"Access is denied to Company <TheCompanyName>" means simply that the user that runs the code does not have access to "TheCompanyName". Check the permissions for that user.
This works RecRef.OPEN(TableID) => This code opens the RecRef in the current company. Your user have enough permissions in the current company
This does not work RecRef.OPEN(TableID,False,TheCompanyName) => This code opens the RecRef in TheCompanyName. As already explained, your user does not have access to TheCompanyName
@da_neal : DataPerCompany = No is not relevant for CHANGECOMPANY (or OPEN(TableID,False,TheCompanyName)) so it does not cause any runtime error.
@da_neal : Table is DataPerCompany=YES, so should not be the problem. But thank you anyway!
@nabil.bamoh@hotmail.com: You describe exactly, what the problem is. My problem is to find out, whether the user has access to a given company, using ReadPermission. I know, I could check in Table Acess Control etc., but my intention was to use the function ReadPermission, which is actually a very handy function. The only problem is, I cannot check, because open command throws a runtime error before I can check. Do you have a good idea?
Anybody else?
Thank you
Thomas
here is how you can achieve what you want "My problem is to find out, whether the user has access to a given company":
code from standard NAV, page 9177 "Allowed Companies"
Language.INIT;
IF Company.FINDSET THEN
REPEAT
// Use a table that all users has access to and check if the user has permissions to open the company.
IF Language.CHANGECOMPANY(Company.Name) THEN BEGIN
Rec := Company;
INSERT;
END;
UNTIL Company.NEXT = 0;
You can combine this code with your previous code (inside the loop)
Thanks for answering. Good idea, I could take that as workaround.
I'm not 100% happy, because of the following:
1: I need to check for a third party tool, thats the reason I need RecRef, otherwise the Code won't compile if third party tool is not there. Not using RecRef would solve my problem instantly.
2: User could have access to the company, but not for that very tool. in the company. For example the person could have access to Finance, but not to Fixed Assets. So checking for Language is not really fool proof.
Maybe, there is still a better way?
Thanks
Thomas
I'm afraid you did not fully get the idea behind the table Language.
The idea is to use a table that every user have read permission like "Language" and do a CHANGECOMPANY on this table to check access to a company... After that, you need to check RecRef.OPEN with READPERMISSION...
Anyway, give a chance to the code below (of course you will need to adapt it to fit your specific need):
Best regards,
Nabil
Thanks a lot, highly appreciated.
It works as desired! At first sight I didn't see the clue....thanks again.
Have a nice day.
Thomas
I'm glad it works.
Don't forget to mark the answer that helped you
Have a nice day too