Greg On Dynamics Ax

Random thoughts about development using Dynamics AX and .Net

X++ and C# Compared

leave a comment »

With the advent of Dynamics AX 2009, the need for AX developers to know .Net is increasing.

I have noticed the AX developer documentation on MSDN getting better and better, here is a section comparing X++ and C# that is well worth a read, check it out!:

X++ and C# Comparisons

Dynamics AX MSDN Developer Center – X++ and C# comparisons


Written by gregondax

June 12, 2009 at 9:00 am

Storing passwords using AX

with one comment

If you need to store passwords in AX there are some application objects, classes and attributes that you can use.  This post details the steps you can take to allow entry of a password in a form, which will be stored in the database.

Password form

1.  Add the password field to your table. This field should be of type ‘CryptoBlob’ which is a container that contains binary data:

Password table field

2. Add an edit method for the password to your table:

//BP Deviation Documented
edit Password editPassword(boolean _set = false, Password _pwd = '')
    CryptoBlob cryptoBlob = connull();

    if (_set)
        this.Password = WinapiServer::cryptProtectData(str2cryptoblob(_pwd));

    return (this.Password == connull()) ? '' : 'xxxxxxxx';

3. Drag and drop the edit method to your form and ensure that the attribute ‘PasswordStyle’ is set to ‘Yes’:

Password form control

4. To retrieve the password you will need a method similar to the following:

static Password getPassword(UserId _userId)
    CryptoBlob cryptoBlob = TutorialPasswordTable::find(_userId).Password;

    return (cryptoBlob == connull()) ? '' :

Disclaimer / Notice / Yada Yada
The safest way to handle passwords is not to store them in the database. The steps described in this post are better than storing the password in the database as plain text, but far from bulletproof. Please ensure that AX security is fully considered if using this method (Table level security, access to code / development etc)

You can download the tutorial as an xpo here from axaptapedia

Written by gregondax

May 21, 2009 at 12:30 pm

Table field groups and reusability

with one comment

Field groups on tables are a great way of arranging groups of related fields to be displayed.

The number one reason being that you set these at table level and not form level, so that you can keep this logic separate from the user interface.

When field groups are modified Ax will automatically update all reports and forms that reference them – which is really cool!

Another thing that not a lot of people know is that you can include display and edit methods in your field groups:

Field group example

Field group example

Related links (from msdn):

How to: Create a field group

Always use field groups in tables

Best practices for field groups

Written by gregondax

May 5, 2009 at 1:17 pm

Accepting Best Practice Errors

leave a comment »

The best practice checker in AX is a vital tool that every x++ coder should use. 
Keeping the count of any BP errors at zero, should be a pre-requisite of 
 any successful build.

However, there will be exceptions where you are happy for a best practice error to stand. You might, for example, be happy for a particular label to end with a full stop.

In code you can accept a BP error by adding the line:

//BP Deviation Documented
display Name getName()
    // . . . code . . .

If the best practice is not contained in code, you can make use of the SysBPCheckIgnore macro, which has been improved in AX 2009 (so that there is no longer a small limit to the number of exceptions).

You should add a line similar to the following to accept a particular error:

<violation errorcode="#compileApplicationCheck" path="\Classes\Class1\sayHello" />


For more information please check out this link on msdn:  How to: Suppress Best Practice Checks 




Written by gregondax

April 21, 2009 at 12:30 pm

Solving Problems during SQL data dictionary synchronisation

leave a comment »

You might get this error message following an upgrade:

Data synchronisation error

Cannot execute a data definition language command on (). The SQL database has issued an error. Problems during SQL data dictionary synchronisation. The operation failed. Synchronise failed on n table(s)

To find out exactly what the problem is you will need to have a look in the Windows event viewer on the AOS server, which will look something like this:

Duplicate record error (Event Log Entry)

If the error is similar to this (I.E of the family “The CREATE UNIQUE INDEX statement terminated because a duplicate key was found”) then you have the following options to solve the problem:

1. If you are not worried about the data in the table then the simplest solution is to drop the table


2. In AX, temporarily disable the index (that causes the duplicate) and use the table browser with filters(using data from the event log) to correct the data.


3.  Use SQL Server management studio to resolve the problem – see this microsoft knowledge base article for a great guide on how to do this:


Please look out for future posts with some tools to help with this!

Written by gregondax

March 29, 2009 at 3:46 pm

Discover hidden AX resources

with one comment

A very popular AX community is, the only problem for English speakers is that the main language is Russian*

This site also publishes an RSS feed for each of its newsgroup, which is great for keeping up to date without having to visit the site.

Click here for the link to the feed in English  (Courtesy of Yahoo Pipes)

This RSS feed (linked to above) was created (by me) using Yahoo Pipes. Yahoo pipes lets you ‘pipe’  information from different data sources and set up rules for processing  that content, if you have a Unix background think of them as Unix pipes.

Using the pipes creator (Which has a great looking GUI!), the programming newsgroup was provided as a feed data source, then loop operators were used to translate the title and description of the feed and  then another operator used to modify the link (so that when you click on the title the source page with full thread is also translated)

Here is the yahoo pipe, where you can view the source:

Yahoo Pipe for

Yahoo Pipe for has been mentioned in these other blog posts:

* With the exception of the sub-forums in different languages, but these are not as busy.

Written by gregondax

February 23, 2009 at 1:35 pm

One thing you should know about the x++ Type ‘anytype’

with one comment

I came across this little gem the other day.

If you declare a variable of type ‘anytype’, assign its value to an enumerated type, then try and reassign it to a date, the code will compile but you will get an error at runtime.

Here is an example

static void AnytypeAssignmentError(Args _args)
    anytype enumOrDate;
    enumOrDate = NoYes::Yes;
    enumOrDate = 06\2\2009; // this should be the date 6th Feb 2009 in x++

And here is the error when you run it:

So it works in a very similar way to the C# 3.0 type ‘var’, with the exception that you will not get a compile error in x++.

The documentation explains anytype should not be used in this way:

If anytype is used as a variable, you must assign a value to it before it can be used or you will get a run-time error. After you have assigned a value to it, you cannot convert it to another data type.

See here for more detail MSDN anytype reference page

Written by gregondax

February 6, 2009 at 1:41 pm