Monday, 18 December 2006

Attaching new database to AOS in Dynamicx AX 4 SP1

We are in the process of upgrading our Dynamics AX application from 3.0 to 4.o. After the upgradation of Application, last week we started the database upgradation in Dev environment. We are using SQL 2000 as our DB for the 3.0 application and we have decided to upgrade to SQL 2005 along with this Dynamics application. So after ruinning the upgrade script in Dynamics AX 3.0 we created a db in SQL 2005 and ran the DB migration application. This went well and when we startetd the AOS after this process, it failed to start and gave following error.

"Object Server 01: Internal Error occurred executing stored procedure when creating session for the AOS. "

After a little investigation we found out that there are two stored procedures(createserversessions, createusersessions) missing from the database that we have created. These are not missing when we use Dynamics AX setup to create the database. So if you are not using the setup to do everthing for you, you have to be prepared to do some stuff yourself. I'm adding some steps here that I went through when I tried to do stuff myself.

In Dynamics AX 4.0 SP1 installation setup, you are asked to enter the account under which want to run the AOS service(not present in Dynamics AX 4.0 installer, so you have to change the account in services to run it properly otherwise you'll receive an error that can be viewed in event viewer).

Once you choose that account in the installer, the installer adds this account in the DB Logins and gives it following access to you DB.

- db_datareader
- db_datawriter
- db_ddladmin
- public

if you change your database after the AOS is installed you have to give the user under which AOS is running the above mentioned rights to your database, and create the procedures (createserversessions, createusersessions). These procedures can be copied from the database that was created by the installer. After you create these procedures give the user, under which AOS is running, Execute permission on these procedures and the AOS should start without any error.

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

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.