Options

Secure one field on a form using the "User Role"-table

krikikriki Member, Moderator Posts: 9,096
edited 2009-11-30 in NAV Tips & Tricks
If you need to secure 1 field on a form, you can do that in different ways:

I give an overview of the different ways (and also add an extra way that I think is the best of all).
1) hardcode each user in the form
+: fast to program the first time
-:each time something in security changes, you need to reprogram

2) use standard security and 2 different forms with some setup
-: you need to maintain 2 forms
+:each time something in security changes, you just change the form for that user in the setup.

3) use a standard role and have some custom code in the form
+: fast to program, because you just create some code in the OnOpenForm
+: only 1 form to maintain
-:each time something in security changes, you just add (or remove) the role from the user

How to do it?
-Create a role in table "User Role". You do NOT need to add permissions to it.

-Create a new field in some setup table (Company setup, G/L Setup, Inventory Setup, Some new setup table, ....). Be sure you use the best setup table to make it easier to find it again (Just don't put a field that must secure something about inventory in the Fixed asset setup).

-In the OnOpenForm-trigger of the form, put this code:
recSomeSetupTable.GET();
CurrForm."The Field".VISIBLE(UserHasRoleInCompany(USERID,recSomeSetupTable."The New Role ID",COMPANYNAME,FALSE,TRUE));

-To add a user that can see that field:
Go into Tools=>Security=>Database/Windows logins=>Add the new role to his login.

Oh. For the definition of function "UserHasRoleInCompany": see here: http://www.mibuso.com/forum/viewtopic.php?t=10695
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Comments

Sign In or Register to comment.