Wednesday, 13 December 2006

How to prevent user from using Hide/Setup features in Right-Click Menu on a form

Last week while we were fine tuning user right in Dynamics AX 3.0 ( a long overdue work), I came across a intresting scenario at a very crucial time. One of the user called me and told me that she dont have access to a specific field. I thought that maybe I forgot to give access to that user group. When I checked the group permissions the access was there. So I coudnt find out why the user dont have access to that field. I was seriously confused. As a last resort to the problem I gave the user Administrator right(a dangerous thing, if user is careless) and still that field was disabled. Then I asked user to get out of her seat and let me see the system in more detail and then I found out that the field she meant was actually hidden by her and thanks to IntelliMorph, the position of that field was taken up by another field (which was read-only). So showing that field solved the problem. This was really frustrating, so we decided to remove Hide and Setup from right click on any from(althought its very silly to think like this, as this is the beauty of IntelliMorph that users can customise interface the way they want to see it, but sometimes we do need to disable it especially when user themselves dont learn how to solve such small issues).

As I started to find out how to remove Hide and Setup from right click. I came to know that these are somewhere in base classes that are not accessable in Axapta. Setup however can be controlled by assigning Security Keys to "SysSetupForm" and then using the security framework to restrict access to this setup form. But I can't find any way to do the same with the Hide functionality. With a little more research I came accross "SysSetupFormRun" class. This class has a very intresting method called "task". Here we can tap into the task that are available from the right-click in a form and do whatever we like with it.

After looking at the task method in SysSetupFormRun, I found out that there is a "Task" macro that hold all the enum for different tasks. So I modified these two piece of code and was able to stop users from using Hide and Setup. Following is the code that I modified.

In AOT->Macros->Task add the following code


In AOT->Classes->SysSetupFormRun->task add the following code

 public int task(int _p1)  
   FormDataSource formDataSource;  
   int ret;  
   if (_p1 == #taskFilter)  
     formDataSource = this.objectSet();  
     if (formDataSource &&  
       formDataSource.queryRun() &&  
       formDataSource.queryRun().args() &&  
   // code change begin  
   if (_p1 == #taskFilterHide or _p1 == #taskFilterSetup)  
     return 0;  
   // code change end  
   ret = super(_p1);  
   return ret;  

This will still show Hide and Setup tasks in right-click menu on a form but nothing will happen as the user clicks on it(not the proper way but it solves the problem).

Note: This will disable these tasks for all users, you can code it to be available for a user group and not available for others.

This posting is provided "AS IS" with no warranties. Use code at your own risk.

No comments:

Post a Comment