Wednesday, December 30, 2009

Yet another AX 2009 development book

This book is in the cookbook style, where you are advised on how to solve certain tasks of Dynamics AX development: Microsoft Dynamics AX 2009 Development Cookbook

Wednesday, December 23, 2009

Identifying the current application environment

There is a ton of ways you can identify what application you are running, when running an application from a set of similar environments like "Development", "Test", "Staging" and so on.

So here's a new suggestion on how you can setup identification like this, without any custom coding in the application: Add the identifier to your Role Center.

Here's how to add the text:
  • Open your Role Center
  • Click Personalize this Page
  • Click Add a Web Part in the zone where you want the identifier to appear
  • Add the Content Editor Web Part
  • Click the "open the tool pane" link that appears in the web part
  • Click Rich Text Editor
  • Add and format a text. For example "You are in the TEST application"
  • Click Save
  • Open the Appearance node
  • Enter a meaningfull title to replace "Content Editor Web Part"
  • Click OK
  • Click Exit Edit Mode (to the upper right)

Monday, December 21, 2009

Suppress report scaling messages

If you want to suppress the infolog message "Report is scaled to xx percent to fit page", you can do it by adding the following statement to your report code, in for example the init method:

Sunday, December 20, 2009

Data Set lookups on Enterprise Portal (EP)

I just spent a complete day trying to make a simple lookup for EP. The lookup was intended to be a lookup on EmplTable, with the ability of filtering on the name of the employees, and it is supposed to return the employee id.

The query behind is built on EmplTable with an inner join to DirPartyTable to get the name.

The easy solution would have been to make a lookup based on a new Data Set, but in trying that I came across two odd limitations in this type of lookup:

  1. You’ll only be able to sort the lookup on the field you want return.
  2. The filter will only show tables from the outer table. The joined tables doesn’t show up.

I find these two facts limiting the usability of the lookup in such degree, that I can’t imagine the lookup was designed this way and I’m assuming it is my own limited skills preventing me from getting the lookup to work like I imagined.

I actually found one other data set (WorkflowUserListLookup), aimed at driving a lookup in standard, built after same model, but it doesn’t seem to be used from the EP application...

Do you have any experience with Data Set lookup based on joined tables and do you know if this lookup could be achieved with a Data Set lookup? Please comment.

B.t.w. I solved the lookup by developing a new user control with a temporary table to drive the lookup.

Wednesday, September 23, 2009

Implement WorkSheet.Copy in \Classes\SysExcelWorksheet

This is how the method should be implemented:
public void copy(SysExcelWorksheet _before = null, SysExcelWorksheet _after = null)
    anytype before, after;

    if (_before)
        before = _before.comObject();
        before = COMArgument::NoValue;

    if (_after)
        after = _after.comObject();
        after = COMArgument::NoValue;

    worksheet.copy(before, after);

Thursday, September 10, 2009

Getting "Runas" back into your life

When testing different uses scenarios on AX, I usually use "Run as..." to open a client as another user. That option is removed from a lot of programs in Windows 2008 (and Vista) and typically won't work on AX configuration files (axc).

I (or actually Google) found this tip on "Norm's PerformancePoint Server blog", on how to get RunAs back:

Wednesday, August 26, 2009

Print images directly to a printer with ShellExecute (in XP)

If you need to write code in AX to print an image file directly to a printer, your first thought might be to call shellExecute like this:

winapi::shellExecute(filename.jpg, '', '', 'print');

This would be fine with other types of files, but in XP image files will be printed via the Photo Printing Wizard, so in this case you simply don't get the file printed.

If you open Tools / Folder Options from an Explorer, go to the tab page File Types and find the type of image you want to print, you can click Advanced button to see that the operating system does when you right click on a file of that type and select print. If available the information will be under "printto". For TIF images on my box, I can see that this is what it will call:

rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_PrintTo /pt "%1" "%2" "%3" "%4"

So in reality this is what you have to call through shellExecute.

Here is a sample job for that:

static void TestPrint(Args _args)
winapi::shellExecute(@'C:\WINDOWS\System32\rundll32.exe', @'C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt "C:\MYIMAGEFILE.TIF" "\\PRINTSERVER\PRINTERNAME" "%3" "%4"');

Tuesday, August 18, 2009

Use keyboard lookup in Product Builder enumerated fields

In the standard product builder you cannot use Alt-Arrow Down to use the lookup on your enumerated fields. This has been an error since the release in version 3.0 and it doesn't seem like it will be fixed before AX 6.0. So I have looked into how this can be accomplished without too much messing around with the product builder.

The reason that you cannot use the lookup from the keyboard is that the AX kernel reasonably enough decides that there is no point in activating the lookup. The key problem is simply to make the kernel accept that there is a point in activating the lookup.

All the enumerated field is based on the table field \Data Dictionary\Tables\PBATmpBuildForm\Fields\tmpString which again is based on the extended data type PBATmpString. The extended data type has no relations on it, and that's the simple reason that the kernel won't activate the lookup.

So to make the kernel activate the lookup I have created a new table, PBASupportEnumLookup, which the extended data type now has a relation to.

Now the kernel will activate the lookup, but it will also try to validate the entered enum values against this table. So I must insert all enum values to the new PBASupportEnumLookup table. I do that in validateField of PBATmpBuildForm before validating the field entry.

The validation part would not be needed if I could get this to work with table relations, because on a table relation I can set the Validate property to no. But unfortunately, a table relation is not enough to make the kernel run the lookup.

Everything else is handled by the product builder code, which already works fine if users in standard use the mouse to open the lookup....

Adding the enum entries to a new table is obviously not the most desirable solution, but it works and it works with minimal footprint in the standard code base. And the users are happy!

Monday, August 17, 2009

Found a Sleep statement in AX 2009 released code

It's awfully nice of the developer to leave the users some time to be able to read progress in the progressbar ;-)

Tuesday, July 7, 2009

Document management on Return Order may apply documents to wrong record

The following bug applies to AX 2009 application build number 5.0.1500.809 and earlier.

When you attach a document or note through document management to a return order line, the document or note might be attached to the current inventory dimension record rather than the return order line.

Repro steps:

  1. Open a new or existing return order from Accounts Receivable / Common Forms / Return order details
  2. Go to the lines of the order
  3. Make one of the inventory dimension fields active, for example Configuration
  4. Activate document management and a note.
  5. Save and close the document management form.
  6. Make a non-inventory dimension field active.
  7. Activate document management, and observer that you don't see you note.
  8. Close document management again.
  9. Make again one of the inventory dimension fields active.
  10. Open document management, and observe that the note now is displayed.

To fix the issue, the ReturnTable form should have a docCursor method similar to the docCursor method on the SalesTable form.

Thursday, July 2, 2009

Longer Support Timelines for Key Microsoft Dynamics Service Packs

See the old and the new timelines here:

Troubleshooting missing EP Development Tools

If you cant see the Dynamics AX Web Project template in Visual Studio, please go through the following list:
  1. Read the blog article "EP Visual Studio Add-In" to check if all components are correctly installed.
    As you can read in the article you must copy the installed templates from the My Documents folder of the user who installed the EP Developer Tools. The files and locations are listed in the article.
  2. You may need to refresh Visual Studios cache of templates after copying them:Open the Visual Studio command prompt (Start \ Programs \ Microsoft Visual Studio 2008 \ Visual Studio Tools \ Visual Studio 2008 Command Prompt) and type devenv /installvstemplates.
  3. If you still don't see the template, remember that you need to select C# as your project programming language before it shows up.
If you can see the template but can't connect to the AX AOS from Visual Studio check the following:
  1. Check that .NET Business Connector has been correctly installed and that the configuration points to the correct AOS instance.
    Check that the user you run Visual Studio with, has login and proper development permissions in AX.
  2. Check that the "Dynamics AX Enterprise Portal Tools" Add-in is correctly installed in Visual Studio. Open Visual Studio / Tools / Add-in Manager to verify that Add-in is correctly installed and configured. If you can't see it, you must reinstall the EP Development Tools.
Additional troubleshooting:

Tuesday, June 30, 2009

Intelligent Data Management Framework For Microsoft Dynamics AX (Pre-Release)

The Intelligent Data Management Framework for Microsoft Dynamics® AX helps administrators optimize Dynamics AX database layout by intelligently monitoring index usage, index layout, fragmentation and query patterns thru indices. The framework allows reduction of the database size by purging transaction records from a set of related entities, while maintaining the consistency and integrity of production data. The Intelligent Data Management Framework provides customers and partners the ability to identify and discover related entities based on Microsoft Dynamics AX metadata and to determine the purging criteria for entities and transactions. The Intelligent Data Management Framework also analyzes the production database to determine current usage patterns and assesses the health of the Microsoft Dynamics AX application. This Framework is compatible with all supported versions of Dynamics AX (Axapta 3.0 SP6 with latest kernel, Dynamics AX 4.0 SP2, Dynamics AX 2009 SP1). Customers on an active maintenance plan can implement this framework to build an efficient data management solution for their implementation.

At RTM, this Framework will include “Archive to Offline” Instance Support.

You can download the framework from PartnerSource (requires PartnerSource login)

This is a pre-release non production build.

AX 2009 Hotfix rollup 2 for SP1 is released

Check the description here:;en-us;971536 (requires partnersource login)

The SYP build number of the rollup is 5.0.1500.809

Tuesday, June 16, 2009

Reading PDF's from the PC

I have just read the training material for a couple of the AX certifications. I didn't want to print it, so I tried to read it directly off my laptop, which with Adobe Reader is a completely disaster. It is completely unpredictable when the reader changes pages while scrolling the document and after reading very few pages you just get tired. I moved the material to my Mac which has a good PDF reader.

Today I found this free reader, which allows me to read PDF's proper on the PC:

Wednesday, June 10, 2009

Dialog error when adding batch tasks to a batch job

If you enter a new batch task to a batch job manually, AX might not initialize the Parameters dialog properly.

AX call unpack of the task class, with the contents of the Batch.Parameters field, but since we are creating a new entry to the table this field is empty.

What AX should do, and what RunBase normally does, is then to call initParmDefault of the task class to initalize it with for example a base for example a base query.

Here is the code to insert in \Data Dictionary\Tables\Batch\Methods\showDialog in order to fix this issue.

// As RunBase normally would do, we need to
// call initParmDefault here, if there are no
// values to unpack
if (!runClass.unpack(this.Parameters))

Thursday, May 28, 2009

Product builder performance tip

I recently had the client/server trace on, while opening the production builder configuration form. Boy, I wish I didn't…

Depending on how complex your product model is, this for generates an excessive number of calls between the client and server.

In my case, the largest group of calls was calls made to \Data Dictionary\Tables\PBALanguageTxt\Methods\label.

The method is tied to be executed on the server, with the "server" keyword.
But, the table itself is cached as EntireTable, and this means that the client is likely to holds its own cache of the values and thus there is no need, and in particular, no gain of forcing AX to run the method on the server.

When I remove the "server" keyword from this method, I get rid of the majority of client/server calls while opening and navigating in this form.

There is however still room for improvement, as the form still generates a huge amount of calls.

Wednesday, May 27, 2009

Create comments with a saved change request number

I have written a small editor script which allows you to insert a pre-formatted comment, with the option to save and reuse a change request number as part of the comment.

After installating the xpo, the new script is avaible in the X++ editor from Script (Alt+R) \ Scripts \ Comments \ SavedComment.

The comments made with the script is formatted like this:
//[date] [current user id] #[change request number]

You can download the script from my SkyDrive:

Use of the script is entirely at your own risk.

Monday, May 25, 2009


A small but not uninteresting little parameter has sneaked its way into AX 2009. The research method on form data sources now allows you to make AX reposition the cursor to the active record you were placed on when calling research.

To do this, call xxx_ds.research(true).

This little parameter saves you the effort of saving data for the record you are on, and use the saved data with the find() method to find the record again, and hopefully (I haven’t tested this though) it has much better performance than the find method. Performance couldn't really be worse than with the find method, so I assume performance is much better when MS introduces this as a new parameter.

Link to MSDN SDK documentation for the method:

Wednesday, April 15, 2009

Free SharePoint Designer 2007

SharePoint Designer 2007 is now free.

You can download the product, as well as educational videos, from here:

If you have bought a license for SharePoint Designer 2007, it can be changed to a license to Expression Web. Read more here:

Monday, March 2, 2009

Creating an image file based on plain text from AX

For the new version of Logica's electronic invoice handling module (eScan) I needed to create a tiff image file from plain text.

Here is a short example on how you can do that through CLR from X++:
static void createTiffFromText(Args _args)
FileName outputFileName = @'C:\Test\MyNewImage.tiff';
str sampleText = "My sample text...";
System.Drawing.Bitmap bitmap;
System.Drawing.Graphics graphics;
bitmap = new System.Drawing.Bitmap(220, 50);
graphics = System.Drawing.Graphics::FromImage(bitmap
graphics.FillRectangle(System.Drawing.Brushes::get_Yellow(), 0, 0, 220, 50);
new System.Drawing.Font("Verdana", 18),
new System.Drawing.SolidBrush(System.Drawing.Color::get_Black()), 0 ,0);
bitmap.Save(outputFileName, System.Drawing.Imaging.ImageFormat::get_Tiff());
// Show the image

Tuesday, February 17, 2009

Adding new financial dimensions to AX

If you want to add a new financial dimension to the system, this has become much easier with the release of AX 4.0 which includes a wizard to do so.

The wizard is started from the file menu, under Tools \ Development tools \ Wizards \ Financial Dimension Wizard. It's located under Development tools because it makes changes in the Application Object Tree (AOT) and you need developer access rights to execute it.

The wizard collects the necessary input and performs the needed changes to the AOT.

The enumerated value suggested by the wizard should not be less than what the wizard suggests, leaving a huge range of numbers for dimensions free to be utilized by Microsoft in future versions.

If your application is hooked up to a version control system, the wizard will check out the elements that need to be changed. It will however not check these in automatically.

There is a small bug in the wizard, making it skip a data type (the bug still exists in AX 2009). Here's is how to fix it (and similar bugs if you find any): Missing datatype in the Fincancial Dimension Wizard

I encourage you to read this blog article on how to design your application for more than the three standard dimensions: Write applications that gracefully accepts new financial dimensions

There's is a limit of 10 on the total number of dimensions. This is due to the AccountPeriodIdx on LedgerBalanceDimTrans. You will hit the maximum number of fields that must be in a primary index on Microsoft SQL Server of you add more dimensions. You could discuss the value if having the index if you have that many dimensions and you could consider changing the index to a subset of the dimensions if you only need to do your reporting on some of them. If you change the index, you are not bound of the 10 dimensions limit.

Wednesday, February 11, 2009

Possible upgrade bug in \Classes\ReleaseUpdateDB41_Administration\renumberEPParametersKey

This method doesn't check if you have and Enterprise Portal (EP) license and thus it doesn't verify that the EP tables exists in your database.

In case you don't have EP it will fail, saying it doesn't know the EPPARAMETERS table. You can ignore this job, even outcomment it, if you don't have EP enabled.

Dealing with changed table or field id's

If you apply an application code layer to an application where table or field id's have been changed from what they used to be, you will lose data during the database synchronization process.

To mitigate this I often see that people export the data first and then re-import it after having deployed and synchronized the new layer.

There is however a smarter, and faster, way to mitigate this issue. What you need to do is to change the id's from the old values to the new values in the SQLDictionary kernel table before the synchronization process starts.

You can of course get into all sorts of trouble if you make incorrect changes to SQLDictionary, so use the helper methods on the ReleaseUpdate class to do your dirty work:

  • changeFieldByAOTName
  • changeFieldByName
  • changeFieldId
  • changeNameByFieldId
  • changeTableByAOTName
  • changeTableByName
  • changeTableId

Look for further information in the upgrade white papers:
How to Write Data Upgrade Scripts White Paper for Microsoft Dynamics AX 2009
Writing Upgrade Scripts White Paper for Microsoft Dynamics AX 4.0

New White Paper: Programmability in Microsoft Dynamics AX 2009

This white paper is for Technical Decision Makers and provides an overview of the wide range of possibilities offered by the programmability in Microsoft Dynamics AX 2009, but it contains some interesting statement on the direction of the development tools. Find the white paper on PartnerSource or CustomerSource

Tuesday, February 10, 2009

Friday, January 30, 2009

Channel 9 video: Dynamics AX Version Control interview from Convergence in Copenhagen 2008

20 minutes interview about version control in AX 2009 with Michael Fruergaard Pontoppidan (Principal SDE) and Morten Jensen (Program Manager) from the Dynamics AX team in Vedbaek, Denmark.

Thursday, January 22, 2009

Adding simple display fields on VS reports

One thing I feel is missing from the documentation for AX Visual Studio reports is a simple explanation or demo of how to create an old school display field in a report.

I could figure out that a DataMethod was needed but it took me some time to figure out how connect the method with a field on the report and how to pass parameters to the DataMethod.

You add a datamethod like this:
[DataMethod(), AxSessionPermission(SecurityAction.Assert]
public static string DataMethod1(string itemId)
string demoString = '(' + itemId + ')';

return demoString;

Then add a field to your design, and in the Expression editor for the field add the code to call your datamethod:


Tuesday, January 6, 2009

Shortcut to the query object of a form data source

Did you now that to get the query object of a datasource, you can write dataSource_q instead of dataSource_ds.query()

For example in the CustTable form you can write:
query = custTable_q;

Instead of:
query = custTable_ds.query();

Monday, January 5, 2009

Bug in EP 2009 when having the debug flag set to true

When you use lookups that are built as user controls, you can get an error like the following error when you cancel the lookup:

A Runtime Error has occured
Line: 198
Error: Sys.ArgumentNull
Exception: Value cannot be null.
Parameter name: panelsDeleting[10]

Here are repro steps to see the bug in Shop Floor Control, which currently seems to be the only place having lookups built as user controls:
  1. Open EP for an employee setup for SFC
  2. Go to Shop Floor Control (This puts you in the Electronic timecard)
  3. Click the "Lock" button
  4. Click "Add lines"
  5. Open the lookup for Reference
  6. Close the lookup without selecting anything, by clicking the webpage somewhere not in the lookup
  7. Try to use any other lookup or move to another record in the grid, if you have more than one line in the grid
The bug is related to a bug in AJAX when it runs in debug mode. If you have debug="true" in the web.config file, change it to debug="false".