Microsoft Dynamics AX 2012 :Use of static construct() and static new() method of a class

Hi All

Use of static construct() method and static new() method of a class

Static Construct():

This method returns an instance of the class. It is a best practice to have a construct method in your class. This method should always be static but can be public or private depending upon the use. When calling a class from another class or job construct method can be used for this


To give you an example, let assume that we have a class ‘AsimConstructClass’ and have a variable ‘Name’ having a parmName method to be set or get


Here I have create a construct method from template, which is returning the instance


I have also create a run method for my logic in a class


Now, finally I have created a job and in this I will get the instance of the class and call the run method in a single call


Static New():

Basically new method is the default constructor of a class invoke when user uses ‘new’ keyword. Mostly it is protected like.


But in some cases we can create our own static new method like

The above example for construct method, shows an infolog with the name ‘Asim’ which is a hardcoded value in a class, So now what if  a user wants to send some input from a another class or job. In order to do this we can create your own individually named static new… methods with different parameter profiles and make it public static

Here newName takes a parameter,


Also in the newName code, it is initializing the instance by calling the construct() method which should be private in this case ,so I made it private


And now in the job I did this


Finally on running it will show



2 responses to “Microsoft Dynamics AX 2012 :Use of static construct() and static new() method of a class

  1. A obj = new A(); —– 1

    A obj = A::Construct()—–2

    May I Know the Difference ????

    Both Were Creating Objects

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s