Skip to main content


Showing posts from April, 2013

Restrict user login for multiple times in ax2009 through X++

Copy Paste the Following Code in startupPost method of info class in AOT.
void startupPost()
// To restrict user login form second login
xSession session;
SysClientSessions SysClientSessions;
UserId currentUserId;
int counter; ; currentUserId = curUserId(); if(currentUserId!=”Admin”)// Allow Admin User to login multiple time
while select SysClientSessions
where SysClientSessions.userId == currentUserId &&
SysClientSessions.Status == 1 // 1 : Login 0 : Logout
session = new xSession(SysClientSessions.SessionId, true);
if (session && session.userId())
} if(counter>=2)
Box::stop(“Already Logged-in : The same user id can’t log in twice.”);
} Please take backup of your application before copying code.

Happy Daxing J

Microsoft Dynamics Ax 2009 Three-Tier Architecture

The three-tier environment is divided as follows:
   ØFirst Tier - IntelligentClient    ØSecond Tier - AOS    ØThird Tier - DatabaseServer
1. The AOS executes Microsoft Dynamics AX 2009 business logic that provides for scalability, flexibility, and better performance for properly designed objects.
2. In this three-tier solution the database runs on a server as the third tier; the AOS handles the business logic in the second tier.
3. The thin client is the first tier and it handles the user interface and necessary program logic.
The Figure below shows Tier Interaction Diagram illustrates the interaction between the three tiers.

--The AOS architecture is highly scalable. --As a business grows and the number of Microsoft Dynamics AX 2009 users increase, expand the capacity of Microsoft Dynamics AX 2009 by adding an additional AOS to the second tier. --The additional server provides load balancing and introduces fail over safety into the environment.

Write into the System Event Viewer from Dynamics AX

Usually it will be difficult to monitor/debug Batch Jobs running on server . For example  if something goes erroneous than it's not easy to find out from where and how its arising.
So we can make use of Event viewer instead of infolog and monitor the status by checking the event viewer .
Writing to the event log in Windows using AX is very easy when you use the EventLog class from the System.Diagnostics namespace. The following job demonstrates how to use the EventLog class.
staticvoid writeEventLogEntry(Args _args) {     System.Diagnostics.EventLog eventlog;     #Define.LogSource("Dynamics AX")     #Define.LogName("Application")     ;
// check if the log already exists if(!System.Diagnostics.EventLog::SourceExists(#LogSource))     { // create new log         System.Diagnostics.EventLog::CreateEventSource(#LogSource, #LogName);     }
    eventlog = new System.Diagnostics.EventLog();     eventlog.set_Source(#LogSource);
// write info entry     eventlog.WriteEntry("<Info&g…

Error: “Request for the permission of type ‘InteropPermission’ failed.”

Many times we would like to call method from dot net assemblies (or) com so we have to assign permission to execute the code .below are ways can be used for CLR and COM
Assign permissions to execute the code (CLR Interop). Like this:
InteropPermission permission = new InteropPermission(InteropKind::ClrInterop); ; permission.assert();
Assign permissions to execute the code (COM object). Like this::
InteropPermission permission = new InteropPermission(InteropKind::ComInterop); ; permission.assert();

CrossCompany keyword in X++

Going to discuss a simple topic which sometimes play vital role in MSD AX. CrossCompany is the Keyword to get the data from another company.

In X++, there is a new keyword crossCompany you can use in a select statement. Additionally, you can add a container with all the company ID’s you wants to include in your select statement.
So, your select statement could look like that: While select CustTable crossCompany : [Test, DAT] { ... Your Code... } (Or)
static void CrossCompany_testing(Args _args)
CustTable custTable;

while select crossCompany * from custTable
print custTable.AccountNum,' : ',custTable.Name,' : ',custTable.dataAreaId;

And let me also show you simple example wherein you can copy your data from one company to another company just in a simple click. So here is the code which you can implement wherever necessary. This code will generate the dialog which asks for user input for ‘fromCompany’ to ‘Tocompany’. static void CompanyCopyTable(Args _ar…

How to use Event Handler in Microsoft Dynamics AX 2012

Microsoft incorporated lot of beautiful new features in Dynamics AX 2012 and one of them is Event Handler. It’s a very nice feature of Dynamics AX 2012 which allows you trigger an event after or before an activity.
So today am going to tell you about these features:
ØIn Microsoft Dynamics AX 2012 how to handle event on different methods / occurrences.

ØIn Microsoft Dynamics AX 2012 how to implement or apply pre or post event handler.
ØHow to develop an event handler step by step in Microsoft Dynamics AX 2012.
ØWhat is new in Microsoft Dynamics AX 2012 from programming point of view?
ØX++ Event handling in Dynamics AX 2012.

You should invoke events over using pre or post events on methods.

Pre-Event Handlers and Post-Event Handlers

An event handler can reside underneath a method node can run either before or after the method runs. You can use CalledWhen property on the event handler node. The CalledWhen property has two values:

• Pre – The event handler runs before the method starts.
• Post –…

GlobalCache / Alternative to GlobalVariables in X++

Many times because of flawed implementation designs, we often need global variables. We may use a table with a key field and a container field for this purpose, but the simplest way of doing this will be using a Global Cache.
The SysGlobalCache class is used by Axapta to store "global" variables and object references. It is implemented as a standard class in the AOT and uses a simple caching mechanism involving nested Map. It is possible to create and use SysGlobalCache objects to implement your own local caching, or to use the instances automatically available through infolog.globalCache() (client-side) andappl.globalCache() (server-side).
A global cache is an instance of class - SysGlobalCache, which is nothing but a Map containing Maps with Userid as Key. These Maps contain the actual value and a key.
In Ax, we have three(infact 4) Global Caches - Infolog.globalCache(), Appl.globalCache(), ClassFactory.GlobalCache().
How to use:
To Set a Value:
static void GlobalCacheSet(Ar…