How-to: Tree lookups in Dynamics AX reference group controls, part 1

This is the first part of a multi-post series that explains how to do a tree lookup in a reference group control on an AX form.

It’s simple, just look at those trees up there…

Oh, seriously…

This is something that keeps coming up on different projects, so I’d like to share how I usually do this.  There are some examples out there which try to describe a very generic solution which can be used in almost any case.  However, such solutions very quickly become very complex.  To keep things simple, I have tried to keep this example fairly specific but adaptable to a wide range of circumstances.  Specifically this example is using a fixed hierarchy structure with a fixed number of levels, each of which will be represented by a different table.

I’ll show how to build the lookup, how to load the tree items on demand to speed up the loading times as well as how to properly select and return the selected record.  I’ll also show some suggestions for how to build the reference group properly so it is easy for the user to understand the information presented to him/her and to understand what to do.

This first part of the series shows how to set up the tables and their relationships.

Continue reading “How-to: Tree lookups in Dynamics AX reference group controls, part 1”

Retrieving Double fields from ADO.NET in CIL code

I recently wrote about how to retrieve DateTime fields from ADO.NET.

If your code is running in CIL, there are some more gotchas, as some conversions that work just fine in X++ will fail when running in CIL.

If you try to retrieve a Double value from ADO.NET and assign it to a record buffer field, the code may run just fine in X++ but when running in CIL you may get this error message:

Error executing code: Wrong argument types in variable assignment.

To work around this, use a local bounce variable of type System.Double, then assign that to the record field like this:

System.Double clrDouble;

...

clrDouble = reader.get_Item( "UNITPRICE" );
item.Price = clrDouble;

There are likely to be other data types causing problems in CIL mode, so I’ll keep posting as I come across them.

Failed to initialize the managed interoperability layer

As with most error messages in Dynamics AX, there are many different situations that can result in exactly the same error message.

Start-SmartDeploy : Failed to initialize the managed interoperability layer of Microsoft Dynamics AX.
At C:\Windows\refresh_staging.ps1:403 char:18
+ Start-SmartDeploy <<<< -Configuration Staging
+ CategoryInfo : NotSpecified: (:) [Start-SmartDeploy], Initializ
ationFailedException
+ FullyQualifiedErrorId : Microsoft.Dynamics.BusinessConnectorNet.Initiali
zationFailedException,SmartDeploy.PowerShell.Commands.StartSmartDeployCommand

I have seen quite a few suggested solutions for this particular one, including checking the versions of the .NET framework, .NET Business Connector installed on both the server and the client, using LogonAs() instead of Logon(), but in every single case I have seen this message, the solution has been….. embarrassingly… simple.

It has always been a case of the problem existing between the chair and the keyboard.

Continue reading “Failed to initialize the managed interoperability layer”

Retrieving date/datetime from ADO.NET into a record field

In Dynamics AX, you can use ADO.NET to retrieve data from external data sources.  This is quite easy to do for text and numeric data types, but not for Date or DateTime data types.

If you try a simple assign, you’ll end up throwing an exception:

blocks.Field1 = reader.get_Item( "REGISTRATIONDATE" );

Error executing code: Wrong argument types in variable assignment.

Using SqlDataReader.GetDataTypeName() to check the data type, it shows DateTime2.  The destination field is a datetime field, but this problem as well as the solution happens even for plain date fields.

So, we might try to use SqlDataReader.GetDateTime() instead, but that results in exactly the same error.

Continue reading “Retrieving date/datetime from ADO.NET into a record field”

Importing data to AX from a fillable PDF form

Recently, a requirement came up for importing data from a fillable PDF form into Dynamics AX 2012.  With the right tools, this is actually quite straightforward.

PDF Labs have a product called PDFTK Server, which is a free download.  However, if you need commercial support from them that’s a paid service.  Likewise, if you want to redistribute the software and your software is not licensed under the GPL (Hint, Dynamics AX is most certainly not GPL-licensed…), you’ll need a redistribution license.  The link to the license is here, and the product download is here.

Continue reading “Importing data to AX from a fillable PDF form”