The given value of type String from the data source cannot be converted to type nvarchar of the specified target column.

Today I experienced this problem while importing models from the build machine into one of the developer machines:

The given value of type String from the data source cannot be converted to type nvarchar of the specified target column.

A quick search on the internet took me to this blog post that explains the importance of initializing / updating your model store after installing CU’s. To initialize/update your model store you simply have to run the AxUtil with the schema command. (Alternative for powershell is Initialize-AXModelStore)

For a full list of AXUtil and PowerShell commands, please refer to MSDN.

Announcing Microsoft Dynamics AX 2012 R2 Services

Hello everybody!

I’m very happy to announce Microsoft Dynamics AX 2012 R2 Services, published byPackt Publishing and authored by Klaas and myself. It is the successor of Microsoft Dynamics AX 2012 Services which was very well received. Based on the feedback you had and based on the new R2 version, we started working on an update in September 2013. We have gone through all existing content, updated and improved it, and added a lot of new content. We are really happy with the result and are excited to hear your reactions.

We are working hard on the book at the moment, the expected release date is May 2014 but you can already pre-order it.

There are also a couple of giveaways that can be won! More information can be found in the full blog post created by Klaas.

http://www.artofcreation.be/2014/03/04/announcing-new-book-microsoft-dynamics-ax-2012-r2-services/

Boek

The Registry.CurrentUser impediment

Today I was working on creating a build process template for AX2012. I will not go into the details about the build process template and the custom activities as these activities will be covered by Joris De Gruyter later on. But still, I wanted to show you guys a nasty little problem I was experiencing yesterday.

The build process threw an exception : ” Object reference not set to an instance of an object

So, this was of course a null reference, but after some investigation ( by using primitive logging because this was running in the agent process 🙂 ) it turned out to be located in this code:

public static string GetInstallDir32()
{
    RegistryKey componentsKey = Registry.CurrentUser.OpenSubKey(regKey, false);
    String installDir32 = componentsKey.GetValue("InstallDir32", null) as String;

    return System.Environment.ExpandEnvironmentVariables(installDir32);
}

It turned out to be the Registry.CurrentUser property that returned null. And then it struck me, the agent ran under a service account s_tfs_build and since this account was never used to log on interactively, the profile of this user was not loaded up to that point.

The simple solution was to log on to the system with the service account so that the user profile and registry hive were loaded. From then on, the Registry.CurrentUser property was properly filled.

Dynamics AX 2012 R2 : XppPrePostArgs changes

Amongst many other changes made in Microsoft Dynamics AX 2012 R2, there has been soms changed to the XppPrePostArgs class too. But before you even read further, please also have a good read through a series of posts made by Joris Degruyter. The series give a nice overview of using models and events to make you code more upgradable. If there was a bible written for AX, this would be one of the first commandments!

In the series of post, Joris explains the use of the XppPrePostArgs class to fetch arguments you want to use in your event handler class. To get the FieldId from the args when the validateField method was triggered, the following code was used:

if(_args.getArg(_args.args().fieldName(1)) == FieldNum(CustTable, DMProjId)

Well, since R2, the XppPrePostArgs class has been modified to extend object instead of XppEventArgs. (MSDN: http://msdn.microsoft.com/en-us/library/xppprepostargs.aspx)
One of the concequences is the absence of the args() method. So when you want to do the same thing as above, you now have to use the following code (it’s a bit simplified and less ugly) :

if(_args.getArgNum(1) == FieldNum(CustTable, DMProjId)

 

AX2012 Editor Extensions

Today I was reading a very interesting post about possible extensions to the editor in AX 2012 and I would very much like to share it.

Basically it explains that the editor is a hosted visual studio editor (that was already clear) and by knowing this, it is also possible to use the extensions that are available there to the editor inside Ax.
The post I read was dealing with the brace matching extension that is available to do automatic formatting of the braces.

You can read the full post here : http://dev.goshoom.net/en/2011/10/ax2012-editor-extensions/