Getting Familiar with X++

23 Mar

In this post, I will make you familiar with the X++ language which is used in Dynamics AX for development. As I have mentioned in my previous post that X++ is quite similar to C#, so all of you have experience of C# won’t have problem in understanding X++. The language is based on Object Oriented Programming principles. You can define access specifiers like Public, Private, & Protected for encapsulation. You can inherit objects, and define polymorphic behavior on methods. I will discuss further in my future post.

So, lets start with the data types that X++ supports. Following are the Primitive data types of X++,

• String (str)

• Integer (int)

• Real (real)

• Boolean (boolean)

• Date (date)

• Enum (enum)

• TimeOfDay (timeofday)

• UtcDateTime (utcdatetime)

• Anytype (anytype)

So these are the primitive data types with the keyword used for it. For example, if you want to declare a variable of type string, you can declare it like that,

str varString;

Need to know little more, Okie, lets make a very small program to understand. In the AOT, there is a Job node. You can create a Job for testing the code. A job yypically holds small X++ programs that are used to test new code. Just right click the Job node and Create new job.

Now write the following codes,

static void Datatypes_string1(Args _args)


str 7 fixedLengthString;

str dynamicLengthString;


fixedLengthString = “Welcome to Carz Inc”;

dynamicLengthString = “Welcome to Carz Inc”;

print fixedLengthString;

print dynamicLengthString;



strfmt function is used to get the formatted string. Following method is used to format a string and change any occurrences of %n with parameter n.

To illustrate this, the next Job will print 100: Welcome to Carz Inc

static void Datatypes_string_strmft(Args _args)


str name;

int a;


name = “Carz Inc”;

a = 100;

print strfmt(“%1: Welcome to %2”, a, name);



Notice that the strfmt function also converts any other data types into string.

Let me describe a little about “anytype” . The anytype data type can contain any of the other primitive data types. The type of the variable data is decided by the first value that is set for the variable.

If you expand “Data Dictionary” node you will see a node named “Extended Data Type”. All the extended data types are based on Primitive data type, however the extended data type has more flavor to the data type like stringsize, label and help text or the configuration key to make the data type specific to configuration settings.

Apart from primitive data types there are Composite data types. These are data types where each variable can consist of multiple other variables.

The different kind of composite data types are:

• Container

• Class

• Table

• Array

Each of the above will be discussed later.

Now, lets talk about the syntax of different statement that controls the flow of the program. I will not go much deep and will just mention the syntax of each statement.

For loop

for (initialization; condition; increment)


//statements that need repetition that will repeat until the condition is true


While loop

while (condition)


//statements that need repetition that will repeat until the condition is true


Do-while loop



//statements that need repetition that will repeat until the condition is true

} while (condition)

If, else if, else

if (condtion1)


//statements that will run if condition 1 is true.


else if (condition2)


//statements that will run if condition 2 is true.




//statements that will run if condition 1 and condtion2 is false.



switch (variable to match any case)


Case 1 :

//statement if case 1


case 2 :

//statement if case 2


case 3 :

//statement if case 3



//statement if none of the cases match



Note : the case statement can be written string, enum, int etc depends upon the type of variable used in switch.

You can test all the statements by creating new job in AOT and observe how the statements behave and to be well aware of writing code in X++.


Posted by on March 23, 2010 in Introduction


Tags: , , , ,

3 responses to “Getting Familiar with X++

  1. Fahad

    April 15, 2010 at 4:39 pm

    good post Zeeshan. Keep writing..

  2. Zarah

    June 20, 2010 at 6:57 am

    Great effort Zeeshan, Keep it up.
    I wana know little about X++ emergence, is it totally a new language or have been there in past also?
    is there any framework for X++ and where u see X++ in near future?

    • Zeeshan Haider Jafry

      July 30, 2010 at 1:44 pm

      Thanks for the appreciation and question.
      Actually, X++ is an specific purpose language not a general purpose. It is designed for the development of Dynamics AX. MorphX which is the IDE uses the .NET framework. X++ provides syntax for direct calls to .NET Framework methods. Keep visiting the blog for further information.


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: