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

kriki
Member, Moderator Posts: 9,121
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:
-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
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!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
0
Comments
-
Another possibility is adding a checkmark to the User Setup table.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions