Tuesday, December 16, 2008

Supply Chain Management in Dynamics AX - a new Microsoft blog

For quite some time now, the MDCC (Microsoft Development Center Copenhagen) team has been nurturing the idea of launching our own blog about the Supply Chain Management area in Microsoft Dynamics AX.

And yesterday, it finally happened!
We posted the first article about Quality Management upgrade process for TQM solution (by Fullscope) users.


I recommend all of you to add this link to your favorites, as we plan to post on a regular basis, and about things important to all of you. That said, I would like to invite all of you to post article ideas or questions related to Microsoft Dynamics AX SCM modules as comments to this message or directly on the SCM blog. We, in turn, will try to cover those in our blog posts.

Thursday, December 11, 2008

Tool for protecting your Dynamics AX source code

"Is there a way to protect/hide my X++ code?"
People asked me this question a million times by now.

To most of them, I described 2 possible ways to go, that I know of:
- Do not share the source code, but instead provide the customers with an AOD file.
- Use a tool that would produce obfuscated code out of your modifications.

Both ways are not perfect, of course. If you provide the code as an AOD file, you need to be sure that the customer does not have X++ license. If you provide obfuscated code, the customer developers (if they are present) will have a hard time interacting with your code. And, eventually, both ways leave the customer at a disadvantage. As soon as the vendor is not there to support (provide fixes in terms of an updated AOD file or XPO with obfuscated code) them for whatever reason, the customer has no way of supporting the add-on solution on their own.

But this post is not about the cons of trying to protect your code.
It's about the possibilities. Today, finally, I can support my previous suggestion #2 with an actual link to such a tool: Next Innovation Code Scrambler Homepage

Here is a screenshot of how the code looks after Code Scrambler is finished with it:

Note, that the tool is not free, and I have not actually tried it out.
But there is a sample project showing the resulting scrambled code. You can download it for a first impression, and contact the company if you are interested in the tool.

Another note - this is not an advertisement, I am not in any way related to Next Innovation Company.

Thursday, November 20, 2008

Personal Experiences with Live Mesh

This post is not going to be about Dynamics AX. It will be about a software product I was thrilled by so much I would like to share it with all of you.

I won't post a detailed description of the product here. You can read that yourself at www.mesh.com. But here is a brief introduction, just to give you a basic idea of what the software can bring into your life.


With Live Mesh, you can synchronize files with all of your PCs (and soon your WM6 phone and Mac as well), so you always have the latest versions handy. Access your files from any device or from the web, easily share them with others, and get notified whenever someone changes a file. Working on one computer, but need a program from another? No problem. Use Live Mesh to connect to your other computer and access its desktop as if you were sitting right in front of it.

Here is a screenshot of the web interface for managing your devices in the mesh:

What I would like to share with you is the personal experiences I had using this software for a month now. In 1 word - fantastic. Live Mesh is still in Beta, but already I can tell you - simplicity is the word. You set it up (takes 5 minutes and is very simple, all you need is a LiveID, which I hope all of you already have). And that's it, you are done. And from then on - it just works. Great!

And here are 2 screenshots of how I use Live Mesh in my everyday life.
Obviously, I have all of my computers meshed, available to me when I need them (they need to be turned on, and have access to internet, of course).

And so far I have 4 folders in the mesh, and I would like to discuss each of them separately:

Personal - I store a backup of my personal data in this folder, which is synced across all my PCs, so that I have it at hand in case I need it. Plus, I have my Personal OneNote workbook in there, with all info I need.
Favorites - Favorites are not synced accross all my PCs, providing the same list on all of them in IE. This is great. This was a feature most of the browsers tried to implement throughout multiple releases. And here it is, as easy as it gets. Any time I bookmark a page, all my other browsers get this page bookmarked as well.
Incoming - this is the folder for file transfer between PCs. Now I don't have to send it to my e-mail every time I need a document scan or something. And, I invite other people as members of this folder, sharing pictures and other documents with them. That easy. And, they get updates every time I add a file, without me having to notify them.
Work - This is my work folder, which I don't sync to my home PC (you can see it is a ghost folder on the screenshot). Any file I work on is automatically synced between my work PCs, so I have an up to date file any time I access it. Extremely efficient.

Well, that's about it. Now, all you have to do is go and try it out yourself.
Have fun!

Friday, October 17, 2008

TableBrowser.NET (a small .NET BC tutorial)

Here is a Visual Studio solution, demonstrating how the Dynamics AX database can be queried through the .NET Business Connector, and how the results of this can be presented to the user in a user-friendly manner.

Here is a screenshot of how it looks:

You can download the solution on axaptapedia.com.

The class to investigate in the solution is the DynamicsAX class. It provides a pretty good interface for reading data out of Dynamics AX.

After opening the solution, make sure to replace the BusinessConnectorNet.dll, pointing it to your AX installation path (if it is not in GAC)

Tuesday, October 07, 2008

The future of programming languages or Anders Hejlsberg/Steve Ballmer Tech-Pep-Talk

Sunday, September 28, more than 350 IT-professionals from the entire country (Denmark) came to MDCC (Microsoft Development Center Copenhagen) to get a 90-minute TechTalk from Anders Hejlsberg and a 15-minute PepTalk from Steve Ballmer.

Click here to see the video.

Wednesday, September 24, 2008

Microsoft Dynamics AX 4.0 data model overview

I have great news for you, readers :)
Recently, on an internal Microsoft discussion group, I received a nice document with an overview of the data model for Dynamics AX 4.0.
After permission was received to publish this document to an external audience, I uploaded it to my personal web-site, so that all of you can download it at a convenient time.

The link is below. Enjoy!

Download AX 40 data model document
Download AX 40 data model document (Russian)

UPD: A newer version of this document does not exist, so I won't be able to post it here

Monday, September 22, 2008

SysMultiTableLoookup - dynamic lookups based on multiple tables

Wow! MSDN for Microsoft Dynamics AX is getting better every day. This is terrific news!! I still remember the days, when all the information was extremely hard to find. It had its own charm though :)
Anyway, this topic is really not about MSDN. It is about lookup forms.

First of all, for the record: I (and the Best Practices document as well) recommend creating custom lookup forms in AOT instead of dynamically coding them in the overridden lookup methods on controls/datasource fields.
But, in reality, this is true only for lookup forms with very large complexity. I won't go into a discussion of why that is the way it is here. :)

Now, back to what I was planning to write about:
In order to build a lookup form from code, developers use the SysTableLookup class.
You can go to MSDN (mentioned above) to read a How-to article on creating a run-time lookup form, as well as take a quick look at the SysTableLookup method descriptions.

SysTableLookup class has evolved over the multiple releases, providing more and more flexibility and control to the application developers.
I would like to publish another extension to this class, SysMultiTableLookup, which I hope will prove useful to members of the AX community.

Short list of features:
- Backward compatible, should cover everything that is present in AX 2009 version of SysTableLookup class
- Allows including multiple tables into lookups with different join types
- Completely based on the Query that you build, no extra parameters (except for the control) are needed to initialize the class
- Allows adding aggregated fields to the lookup
- Displays fields based on Boolean Enum as check boxes
- Allows to specify alternative labels when adding fields to the lookup

New download link, as Axaptapedia seemed to mess up the file

You can download the project from axaptapedia.com.

It has (to some extent) been tested on Axapta 3.0 SP3, AX 4.0 and AX 2009.

Also included in the project is a tutorial form, showing 4 examples of dynamic lookups using the new class. After importing the project, make sure to try out the form, and use it for future reference for code examples and other inspiration.

Tuesday, September 16, 2008

SysInfoAction class description - Improve your Infolog

In the last couple of weeks I have been asked about this a number of times, so I decided it would be a good idea to describe what the class can do for you.

In just a few words, this class helps you interact with your users better, helping them perform some desired action (predefined) on request. This will save some time for the user, providng for a better user

There is a number of classes already present in the system.
Just to name a few used the most:

JournalInfoAction - allows navigating to the specified journal line. This is used, for example, when checking the journal lines before posting.
SysInfoAction_Editor - opens the editor in the specified method on the specified line/column. Primarily used for development purposes.
SysInfoAction_FormRun - opens a specified form, setting focus to a specific control, if required. There are many extensions of this class, allowing for more control over what is to happen.
SysInfoAction_MenuFunction - same as the one above, but the input is a menu item that is to be launched on user action.
SysInfoAction_newWindow,SysInfoAction_AOTproperties - both are used to ease up the dev's life a bit. The first one opens the specified AOT object in a new window, the latter one - the properties for the object.

And so on...

I had to create one extension of this class yesterday as well, while doing a small tool we use inside our team. The requirements were to launch a specific external application, specifying a number of files as command-line arguments. WinAPI ShellExecute can do exactly that. So I create a simple wrapper around the WinApi::ShellExecute method that is accessible as an infolog action.

Here is an example of how this class can be used:

You can download the class from axaptapedia.

The output of the infolog, in this case, would look similar to this:

Infolog output

One other thing worth mentioning about these classes is the method infolog.infoActionObject(). This is not used as often, but provides a greater control over the infolog action by allowing interaction with an open object, like a form.
This is used in AX journals (Inventory Transfer journal, for a specific example, if you wish). Whenever you check the lines of the journal (before posting), you get an infolog in case of errors, which allows to navigate to the specific line with the error. The navigation occurs in the journal lines form currently open, which is much better than opening a new form for each line.
In order to use this, simply specify the object that needs to be available when executing the infolog action, using the method mentioned above, like the following:

infolog.infoActionObject(this); //if called from the method on a class/form, for example

For more information, check out the article on Axaptapedia (I hope it will get expanded over time :))

Tuesday, August 12, 2008

Another useful Editor Script for developers

In AX the principle of upcasting is used quite a lot. Some examples coule be the RunBase hierarchy or the InventMovement class hierarchy. Basically, the base (or super) classes contain the main part of the hierarchy logic, while subclasses only override a couple of methods performing actions specific to this class.

When browsing the AOT, trying to find a specific line of code (debugging without the debugger, basically), you often find yourself in a situation when you lookup a definition of a method from a derived class, and end up in this method of the base class instead (because upcasting was used in the code in question). And every time you need to see the same implementation in the child class, you need to go back to the AOT and open it from there manually.

Well, not any more.
Here is a small editor script, that you can use to navigate to an overridden method of a derived class.

I created 2 versions of the same script, one using xReferences, the second using Dictionary class. The xRef one, generally, works faster once the xRefs for the class hierarchy is updated (happens the first time you use the script). So I am not posting the second script version. If anyone is interested in that version specifically, let me know and I will send you the code.

I made a couple of small changes to the script since my previous post (which I deleted), making it possible to import the script without compilation errors into AX prior to verion 2009. Sorry for that :)

You can copy-paste the code for the script from axaptapedia.com (There is a problem with copying over the code from blogger site directly)

You can read more about Editor Scripts and how to use them here

Enjoy, and get back to me with any comments or suggestions, posting them as comments or e-mailing me directly

Thursday, July 10, 2008

Microsoft Dynamics AX 2009 Keyboard shortcuts

A whole lot of new and handy shortcuts have been introduced in Microsoft Dynamics AX 2009. To name just a few, that are very important for developers:
Ctrl+Shift+P opens the Projects
Ctrl+Shift+I (from AOT or projects) opens the import project window, etc.
Alt+F1 will return you to the main Dynamics AX window (especially useful for those fond of Tabax)

A fellow tester from Dynamics AX Client team, David Kidder, created a document containing the shortcuts available, grouping them according to where they are used in the application.

One thing I would like to highlight is that you don't need to work for Microsoft to create this list. You can get the list of all available shortcuts in the system by launching the client (Ax32.exe) with the -internal=GENERATEKEYHELP command line argument. The xml file with the shortcuts, AxKeyDump.xml, will be placed into the Client\Bin folder of Dynamics AX.

It is an extremely useful document, and I suggest everyone prints it out and hangs it by their desk.
The download link can be found below:
AX 2009 Keyboard Shortcuts.docx

Warning: The file is in Microsoft Word 2007 format, but I am sure all of you have that (or the converter) by now.

UPD: Also check out the cool looking poster with shortcut keys for end users to hang by their desk.

Tuesday, July 08, 2008

AX 2009 RTM Demo Data released

Finally, the new demo data for AX 2009 has been released. Partners and Customers can download it now from the links below:
Partner Source - download (Requires partnerSource login)
Customer Source - download (Requires CustomerSource login)

You will find two different data sets:
Contoso Base: Contoso base demo data, with almost no transactional data
Contoso Trans: Contoso transactional demo data, with 2 years of transactional data from Jul 1, 2006 to Jul 1, 2008 for some modules.

Demo Company Overview

The Demo Data set for Microsoft Dynamics® AX 2009 is no longer based on the Global Trade and Manufacturing Company. Based on market feedback we have created a new Contoso Entertainment systems group of companies. It comes with 2 fiscal years of transactional data that enable us to demo our stronger Business Intelligence story and Role Center pages, while allowing us to easily expand the demo data story in future releases as we expand Microsoft Dynamics® AX’s functionality footprint.
Contoso Entertainment Systems (CES) is a home electronics manufacturing, distribution and retail company that includes a Professional Services department. Its headquarters are in the USA with a key distribution subsidiary based in Germany and it works with the relevant currencies. CES distributes televisions, projectors, Digital Video Recorders and Players, and audio receivers. It manufactures speakers and assembles home theatre systems. CES’s customers are primarily based in North America and Europe and include Major Accounts (such as hotel chains), Wholesalers (of differing sizes), Retail stores (that are self-owned and operated), as well an internet storefront.
The legal and physical structure of CES is setup as follows:
• CEC – Contoso Entertainment Consolidation, based in USA
• CEU – Contoso Entertainment USA, Headquarters based in USA
o Site 1: Production of all speakers
o Site 2: Assembly of home theatre systems and Services
o Site 3: Production of Standard speakers
• CEE – Contoso Entertainment Europe, Distribution subsidiary company based in Germany
o Site 4: Distribution, Assembly and Service of all products
• CVC – Virtual company that includes table collections from CEU and CEE.

The downloads for Contoso Entertainment Systems demo data offers transactional data for Basic, Administration, General Ledger, Bank, Fixed Assets, Accounts Payable, Accounts and Receivable, Inventory Management, Intercompany, Production, Master Planning, CRM, Project, Expense Management, and Human Resources modules, and is intended to demonstrate these modules’ functionality. It also offers base data (i.e. no transactions) for the Product Builder modules. There is no demo data available for Payroll and Cost Accounting modules.

A lot of work has been put into these demo data files, to allow the users to investigate most of the functionality of the applicaton.
Thanks for this.

P.S. Just received some more input on the dataset, so decided to edit the message and post this interesting info as well

Thursday, May 29, 2008

EditorScripts.addIns_OpenInAOT - version 2

A long time ago, I posted an editor script for opening objects selected in the editor in AOT (link to that post)

Yesterday, miklenew from AxForum posted an editor script for AX 3.0 that opens a new AOT window with the object currently selected in the Editor, that works a little differently and also allows to open objects based on variable type. You can view the original post here.

Today I modified this code, extending it a bit and adding support for Dynamics AX 4.0 and Dynamics AX 2009 (For version 3.0 use the code posted on AxForum).

public void addIns_OpenInAOT(Editor e)
TreeNode treeNode = TreeNode::findNode(e.path());
xRefTmpReferences xRefTmpReferences;
Column nCol = e.columnNo() + 1;
Line nLine = e.currentLineNo() + 1;
xRefTmpReferences = xRefCreate::makeTmp(infolog.lastxRef());

select firstonly xRefTmpReferences
order by Column desc
where xRefTmpReferences.line == nLine &&
xRefTmpReferences.Column <= nCol;

if (!xRefTmpReferences)

treeNode = TreeNode::findNode(xRefTmpReferences.path());

if (treeNode)

As you can see, the code is very simple and utilizes the xReferences.
But the great thing about it is that updating the cross references is not required for this code to work, as it updates them on the fly for this specific AOT node.
I think this is a must have method for each application developer out there. :)

Tuesday, May 13, 2008

AxPaint / AxAssist for Axapta 3.0, AX 4.0 and AX 2009

First of all, I would like to remind anyone interested of what AxPaint is. This is a small activeX component + a small xpo, that will allow you to change the background image of your application to whatever image you like.
You can find installation instructions, screenshot and a more detailed description through the link below:

Well, the tool has recently been updated with support for all versions of AX starting with version 3.0.
The download link for the new (and, most probably, final) version of this tool is AxPaint.
Enjoy! :)

Also, it is hard not to mention another development tool from the same author, AxAssist. Sadly, it is not free, but it is still worthwhile to check it out - maybe that's something you company would be interested in buying. There is a Trial version you will be able to play around with for 30 days. The homepage for the tool is - www.axassist.com

Monday, April 28, 2008

SysFormEnumComboBox - class allowing to show only some of the values for a comboBox

In Microsoft Dynamics AX 2009, a new class has been created, that got my attention recently after yet another question about this sort of thing was asked by a fellow Dynamics AX developer.

Often enough, we need to restrict the user selection from a particular ComboBox. Creating a new BaseEnum specifically for this purpose is a really cumbersome solution, which later might lead to problems of maintenance.

Originally, the SysFormEnumComboBox was designed to be used on forms to provide for this behavior. I modified the class slightly to allow for usage in RunBase Framework classes.
To demonstrate, how this class can be used, I modified the tutorial_RunBaseForm class and form, showing both scenarios: adding the control from the dialog method of the class, as well as adding it manually in the form design and methods.

To use this class, you need to know only one static method:
public static SysFormEnumComboBox newParameters(
FormRun _formRun,
int _comboBoxControlId,
enumId _enumId,
Set _allowedEnumValuesSet,
Form _form = null)

And here is an example of how you would use it:
sysFormEnumComboBox = SysFormEnumComboBox::newParameters(element, 

which means that the control ComboBoxOnForm will be bound to BaseEnum InventTransType, containing only values, found in the Set enumSet.

You can download the project for versions 4.0 and 2009 of Microsoft Dynamics AX through the following link:

P.S. It is also worth mentioning, that this class does not provide support for grids. It requires a stand-alone control, not bound to a database table field.

Wednesday, March 26, 2008

Microsoft Dynamics AX 2009 CTP3 release is available on PartnerSource

Finally, the CTP3 release is available for download from PartnerSource.

It is, as usual, a VPC image that you can install on a standalone computer.
Be warned, that the size of the image is huge - about 7 Gb in 3 parts.

Here is a short description of the toolkit:

The Demonstration Toolkit for Microsoft Dynamics AX 2009 Pre-Release (CTP3) contains marketing materials, demonstration scripts, and a Virtual PC image containing a full installation of Pre-Release of Microsoft Dynamics AX 2009. You can obtain the Demonstration Toolkit on DVD from a Microsoft Dynamics Partner, or you can download the contents of the DVD using the links on this page.

Download link (Requires PartnerSource access)
It would be very interesting to hear any comments you might have about the CTP release, as well as about any major (and minor, as well) bugs you might find in this PRE-release. Feel free to e-mail me or leave a comment under this post.

P.S. (One day later)
An ISO image was also made available today. It is much lesser in size, and is an image of the installation CD + licence file for CTP3 release.
Download link (Requires PartnerSource access)

Friday, March 14, 2008

AxForum in English / AxForum auf Deutsch

There was a blog post recently about using Google Translate! to read posts on AxForum, one of the best communities there is on Microsoft Dynamics AX.

Here is the direct link to AxForum translated from Russian to English with Google Language Tools (Google might think you are a virus, so you in some cases will have to input a verification line to continue)

What I would like to point out and promote here, is the fact that AxForum actually has support for User Interface in English and German, and sub-forums in both languages:

AxForum in English
AxForum in German (auf Deutsch)

There aren't many posts there at the moment, but all AxForum members would be glad to help anyone who posts a question in one of these sub-forums (if they know that language, of course). So don't be shy and visit the sub-forums when you are in doubt or have a problem you cannot solve on your own.

You can find the original post about Google and AxForum here

Monday, March 10, 2008

Microsoft Dynamics AX 4.0 Service Pack 2 is available for download

Just a short announcement today:

The Demonstration Toolkit for Microsoft Dynamics™ AX 4.0 Service Pack 2 (SP2) contains marketing materials, demonstration scripts, and a Virtual PC image containing a full installation of Microsoft Dynamics AX 4.0 SP2.

Download link (Requires PartnerSource login access)

P.S. Just a warning for anyone unaware - the VPC image is very large, as it cotains an operating system, SQL server, AX install with demodata, etc., total size exceeding 9 GBs)

Saturday, March 08, 2008

Hotkeys and Find vs Filter in Dynamics AX 2009

In Microsoft Dynamics AX 2009 a number of changes regarding Filtering in grids were introduced. I would like to talk about one of them today.

As most of you know, in AX 4.0 the Ctrl+F hotkey was replaced with Ctrl+K, which was very confusing for customers that were using AX 3.0 at the time. (see one of my previous posts with a .dll go fix that)

Well, I am happy to tell you, that Ctrl+F is now back as a regular (not Global) Find option in AX 2009. But Ctrl+K is also available. So it was decided, that having to identical commands is not really smart. So now they actually perform different actions.

Ctrl+F is Find
Ctrl+K is Filter = Filter by Field from the context menu on the grid line.

Now, you might wonder what the difference is. I will explain it on an example:

You have a grid with items of different Item Type (BOM, Item, Service) and different Item Group (Parts, Bulbs, etc.)

Scenario 1: (Notice the dialog caption is Filter)
1. Press Ctrl+K on Item Type "BOM"
2. Press OK (the value BOM is already inserted in the search field).
3. Only BOM items are shown
4. Press Ctrl+K on Item Group "Parts"
5. Press OK (the value Parts is already inserted in the search field).
6. Now only BOM items with Item Group = Parts are shown.

Scenario 2: (Notice the dialog caption is Find)
1. Press Ctrl+F on Item Type "BOM"
2. Input "BOM" and press OK (you have to input the value you are searching for every time).
3. Only BOM items are shown
4. Press Ctrl+F on Item Group "Parts"
5. Input "Parts" and press OK.
6. Now only items with Item Group = Parts are shown, including both BOM and other Item types.
So, basically, all previous filtering on the grid was removed before applying the new search criteria.

As a side note, I would also like to mention, that some changes were made to hotkeys in the Editor: Now, Editor Scripts are opened using Alt+R hotkey, instead of Alt+M, as in previous AX versions. (Alt+M was reserved for the global menu toolbar, which is one of the new features in AX 2009 as well)

Find all reports with datasources innerjoined 1:n

I haven't really written much X++ code in the past 5 months, so a work-related task on X++ was like a holiday :)

I needed to find all reports, in which there is a child datasource (on some level) that is inner joined with the parent datasource as 1 to many.

Here is one of the possible solutions of the problem.
I would also want to talk a little bit about different methods used in this scenario, in case some of you are still unfamiliar with those:

static void FindReports(Args _args)
Report report;
TreeNode treeNode = TreeNode::findNode(#ReportsPath);
TreeNodeIterator iterator = treeNode.AOTiterator();
QueryBuildDataSource qbds;

boolean find1nInnerJoin(QueryBuildDataSource _qbdsParent)
int i;
QueryBuildDataSource qbdsChild;
boolean ret;
for (i = 1; i <= _qbdsParent.childDataSourceCount(); i++)
qbdsChild = _qbdsParent.childDataSourceNo(i);
if (qbdsChild)
if (qbdsChild.joinMode() == JoinMode::InnerJoin && qbdsChild.fetchMode() == QueryFetchMode::One2Many)
return true;

if (qbdsChild.childDataSourceCount() > 0 && find1nInnerJoin(qbdsChild))
return true;
return ret;

treeNode = iterator.next();
while (treeNode)
if (treeNode.sysNodeType() == 202) //Report
report = treeNode;
if (report && report.query().dataSourceCount() > 1)
qbds = report.query().dataSourceNo(1);
if (find1nInnerJoin(qbds))
treeNode = iterator.next();

Here are some keypoints:

1. Notice the use of TreeNodeIterator class. This is an example of an Iterator applied to the AOT. Very convenient and easy to use. You can read more about this class and its methods on MSDN

2. Notice the use of BaseEnums QueryFetchMode and JoinMode - I have seen many developers specifying integer values instead. I would suggest using these enumerations instead - the code will be much easier to read later on.
I don't know the enum for return value of method treeNode.sysNodeType() though. So if someone does, write a comment - it would be nice to know.

3. Notice the use of an implicit conversion from a base type object (TreeNode class) to a derived type object (Report). This is allowed, because, as you know, X++ type system is a "weak" type system. But beware, because this might lead to run-time errors. For example, if you call a method on the Report class, that is not inherited from the TreeNode class, you must be absolutely sure that the object is actually of type Report. Otherwise, you will get a run-time error.
This is why before the conversion, I verify that only Report objects get through to the following code.

4. The last, but not least: Notice the methods exposed by the QueryBuildDataSource class - basically, it allows to receive a lot of information about a specified query. Again, for more information, refer to MSDN

Saturday, February 02, 2008

A not-so-easy game about Earth

Here is a fun game that challenges your brain. It's not really about AX, but can drive you crazy as well :)
I am still stuck on level 9, and it turns out there are so many places I haven't even heard of, not mentioning actually placing them on the world map. Very entertaining!

Thursday, January 17, 2008

Creating and Posting Inventory ProfitLoss journals in DAX using .NET Business Connector

Yesterday, I was helping a friend from Canada create a small solution that would create and post ProfitLoss journals in Microsoft Dynamics AX 4.0 using .NET Business Connector.

In the end, we created 2 solutions - one was entirely written in X++, and only simple class static method calls were made from C#. The other was completely written in C#, using various classes, available with .NET business connector.

I uploaded the solution to the following link, in case anyone would be interested to download it and play around with it or use in their projects.
Download ProfitLossPostingAppl

Also, here is the source code - it is a small console application, and I tried to add as many comments as possible, so that even complete X++ beginners would be able to easily read the code.

Notice that in the solution, there is a reference to the business connector dll.
You can find the Microsoft.Dynamics.BusinessConnectorNet.dll in the Client\Bin folder of your Dynamics AX installation. This dll is what provides you with access to the Dynamics AX application and the set of classes to use AX tables and classes.

using System;
using Microsoft.Dynamics.BusinessConnectorNet;

namespace ProfitLossPostingAppl
class AxProfitLossPostingEngine
static void Main(string[] args)
Axapta ax = new Axapta();
// company name, language, object server, configuration
// this uses Windows Authentication
ax.Logon("cmul", null, "localhost", null);

// Start a transaction

// AxaptaRecord is a class that allows to work with Tables in AX
AxaptaRecord header = ax.CreateAxaptaRecord("InventJournalTable");
AxaptaRecord journalName = ax.CreateAxaptaRecord("InventJournalName");
AxaptaRecord line = ax.CreateAxaptaRecord("InventJournalTrans");
AxaptaRecord inventTable = ax.CreateAxaptaRecord("InventTable");
AxaptaRecord warehouse = ax.CreateAxaptaRecord("InventDim");

// You can call static table methods using the following syntax
journalName = ax.CallStaticRecordMethod("InventJournalName", "find", "IPL") as AxaptaRecord;

// There is a set of predefined methods on the AxaptaRecord class, like the clear(), initValue, DML operations, etc.
// You can call table object methods as well, not only static
header.Call("initFromInventJournalName", journalName);

line.Call("initFromInventJournalTable", header);
// You cannot use table fields directly as in X++. Instead you have set/get methods
line.set_Field("itemId", "B-R14");

// Instead of using static table methods (like find) you can execute a direct SQL statement and receive the result in the AxaptaRecord object
inventTable.ExecuteStmt("select * from %1 where %1.ItemId == 'B-R14'");
// If you receive more that one record you can iterate through them using Next (as in AX)
line.Call("initFromInventTable", inventTable);

line.set_Field("Qty", 160.0);

warehouse.set_Field("InventLocationId", "MW");

warehouse = ax.CallStaticRecordMethod("InventDim", "findOrCreate", warehouse) as AxaptaRecord;

line.set_Field("InventDimId", warehouse.get_Field("inventDimId"));

// Notice AxaptaRecord is passed by reference here
ax.CallStaticRecordMethod("InventJournalTable", "initTotal", header);


// You can call static class methods the same way you call table static methods, but using a different method on Axapta class
// So in case you wrote the posting in X++, you would be able to call it, passing the JournalId as the argument
// int numOfLinesPosted = (int)ax.CallStaticClassMethod("DEV_ProfitLossEngine", "postProfitLossJournal", header.get_Field("JournalId"));

// Or, you can use the AxaptaObject class to accomplish the same from C#
// You can initialize a new class using the Axapta class method
// AxaptaObject journalCheckPost = ax.CreateAxaptaObject("InventJournalCheckPost");

// Or using a static method, if that suites your needs better
// Notice here that an object of type AxaptaRecord is passed into a method that expects InventJournalTable as the argument
AxaptaObject journalCheckPost = ax.CallStaticClassMethod("InventJournalCheckPost", "newPostJournal", header) as AxaptaObject;
// You can object methods the same way you would on a table
journalCheckPost.Call("parmShowInfoResult", false);
journalCheckPost.Call("parmThrowCheckFailed", true);
journalCheckPost.Call("parmTransferErrors", false);

int numOfLinesPosted = (int)journalCheckPost.Call("numOfPostedLines");

Console.WriteLine(String.Format("{0} line(s) have been successfully posted", numOfLinesPosted));
Console.WriteLine("JournalId is " + header.get_Field("JournalId"));
Console.WriteLine("Press any key to continue ...");

catch (Exception ex)



P.S. Of course, it would probably be a better idea to use classed InventJournalTableData, InventJournalTransData, etc.
But for the simplisity of the example, everything is done directly with tables.

Wednesday, January 16, 2008

Microsoft Dynamics AX 2009 - some of the new development features

Alexei Eremenko from Microsoft Russia has posted a number of articles about the new features that will be available in DAX 2009.
The original link, which is in Russian (but the main thing to look at is the code, which is universal): http://blogs.msdn.com/aeremenk/archive/2008/01/15/7118429.aspx

I would like to make a brief review of the features he talked about for the English-speaking population and another feature I liked that Alexei did not mention.

Let's start with the support for union in SQL statements (but only when using Query* classes).

query = new Query();
query.queryType(QueryType::Union); // The other value of QueryType is "Join"

Another Exception type has been introduced, which now actually allows to catch the DuplicateKey exception:

Table t;

while select forupdate t
test.Field1 = ‘xyz’;
catch ( Exception::DuplicateKeyException, t )
infolog(‘Record already exists - ‘ + t.Field1 );

The bulk DML statements now allow using inner/outer joins, and you can access the result of the update_recordset operation to get the number of rows that were updated:

update_recordset batchJob setting
Status = BatchStatus::Canceled,
EndDateTime = thisDate,
Finishing = 1
where batchJob.Status == BatchStatus::Cancelling
notexists join batch
where (
(batch.Status == BatchStatus::Ready ||
batch.Status == BatchStatus::Executing ||
batch.Status == BatchStatus::Hold ||
batch.Status == BatchStatus::Cancelling)
&& batch.BatchJobId == batchJob.RecId

rowsUpdated = (batchJob.RowCount() > 0); // get the number of updated rows with rowCount()

And, the feature I enjoyed, is that we now have crossCompany support in X++. Meaning you can access data from tables from a number of companies in one query.
Here are code snippets to explain what I mean:

static void DataBaseAccess_CrossCompany(Args _args)
InventTable inventTable;
container companyContainer = ['IN1', 'QMS'];
while select crossCompany : companyContainer inventTable
where inventTable.ItemId == "B-R14"
print inventTable.ItemId, " -- ", inventTable.dataAreaId;

This code will print ItemId from 2 companies, even though InventTable has the property SaveDataPerCompany set to Yes.

The same functionality is available with the Query classes:

static void DataBaseAccess_CrossCompany_Query(Args _args)
Query query = new Query();
QueryBuildDataSource qbds = query.addDataSource(tableNum(InventTable));
QueryRun queryRun;
InventTable inventTable;
qbds.addRange(fieldNum(InventTable, ItemId)).value(queryValue("B-R14"));


queryRun = new QueryRun(query);
while (queryRun.next())
inventTable = queryRun.get(tableNum(InventTable));
print inventTable.ItemId, " -- ", inventTable.dataAreaId;

If you don't add any specific company ranges, the data will be retrieved from all companies you have access to.

Microsoft Dynamics AX 2009 has a lot more to offer, of course. But enough for today.