Dynamics Ax: X++ what’s new

Hi All!

As you’ve probably already heard the new major release of Dynamics Ax is out and it’s called Microsoft Dynamics Ax! I have been to the Ax7 technical preview conference so I’ve already prepared some content for you and now that the release is official I can share it all. Dynamics Ax comes along with a whole bunch of new goodies and the new compiler being the biggest one. This allowed Microsoft to implement a whole bunch of new keywords in our beloved X++ language.

This keyword for variables

We already had the this keyword for calling methods, but now we can also use it to assign values to variables or pass them.

Static constructors and fields

You all probably know this but a static variable is a variable shared among all instances of a class. And what do all we pattern loving developers think? Exactly the singleton pattern is finally possible without dirty caching tricks!

The static constructor is called TypeNew()

  • These are automatically called before the first use of a class.
  • These are called once for each type and each session.

Var variables and declaration

Declaring a variable as a var type (implicitly typing) will let the compiler decide which type it is, therefor you don’t have to. When a var variable is assigned to a type this cannot be changed anymore.

And from now on you can also declare anywhere!

Const/readonly variables

  • Const: This is a constant and can only be assigned a value when declaring it.
  • readonly: The value of this variable can be changed at runtime but only through a constructor.

Public / protected / private access modifier for variables

Data encapsulation can now implemented decent because as in C# we can declare our variables public, protected or private. This makes code more robust when implemented well.

  • public: Access is not restricted.
  • protected: Access is limited to the containing class or types derived from the containing class.
  • private: Access is limited to the containing type.

The difference with C# is that the default modifier still is protected, because changing it to private would break too much existing application code.

Finally in try/catch statements

Finally! A way of executing code when either the entire try statement has finished or a handled exception has occurred.

Typed exceptions

And exception handling even get’s better! Because now we can handle any exception that extends from System.Exception. Which is a big leap forward when using the .NET framework.

Using keyword

No more worries about memory leaks when consuming unmanaged resources because now you can use the using keyword for objects that implement IDisposable.

Extension methods

What if there was a way to add methods to an object without modifying it in your customization layer? Well now there is, it’s called extension methods and the principle is the same as in C#.

Some reminders when using this:

  • Use these in a static class.
  • The name of the class must have the suffix “_Extension”.
  • The method is public.

Declarative enventing: with pre and post events

In 2012 we already had eventing, but one minor flaw most developers had issues with was that you had to change the object you where subscribing to. Since we run fully in IL it is possible to subscribe to an event without modifying the sender object.

For instance the DirPartyTable has a delegate method dirPartyDeleted.

 

Using clauses

Remember the days when you want to use a .NET library and you always had to write the entire namespace? Well those days are over.

Enjoy your coding with all the new goodies! 🙂

Enterprise portal: work items for Purchase orders

Hi all,

Those of you who work with workflow in the Procurement flow might have encountered the following problem. The client wants to approve Purchase Orders through the Enterprise Portal, but for some reason the work items are not visible, while they are visible in AX Client.

Fair enough, you’d say, there actually is an option in the workflow to enable or disable this from the Enterprise Portal. Weird enough, the checkbox is checked and there is no other reason why actions on work items would be blocked.

The problem is an actual standard Microsoft bug.

There is a difference in workflow elements that can be used, ‘Approve purchase order’ and ‘Approve purchase order, editable’. The latter makes it possible for reviewers to edit the Purchase Order they need to approve. The former obviously doesn’t. Only when the latter is used, work item actions become unavailable in the Enterprise portal.

Open AOT>Workflow>Approvals

You will find 2 approval elements: PurchTableApproval and PurchTableApprovalEdit

Elements

If we compare these two elements:

Comparison

It is clear that the ‘ActionWebMenuItem’ is missing in the properties of the ‘PurchTableApprovalEdit’, for Approve/Reject/RequestChange. To solve our problem, we will simply need to fill these in on the Edit-element:

Approve: EPPurchTableApprovalApprove
Reject: EPPurchTableApprovalReject
RequestChange: EPPurchTableApprovalRequestChange

On the headnode we’ll need to fill out three missing fields as well:

Comparison2

DocumentWebMenuItem: EPPurchTableInfo
ResubmitWebMenuItem: EPPurchTableWorkflowReSubmit
DelegateWebMenuItem: EPPurchTableApprovalDelegate

This will fix the work item problem! Microsoft has stated that workflow functionality will change in AX7 and so this issue will not be resolved for AX2012.

MS SQL Server index maintence

Hi,

As we all know index maintenance is important especially on large Dynamics Ax databases, but often I see installations where there are little or no maintenance plans or all kinds of exotic scripts. Therefor I want to show you guys the SQL Server Maintenance Solution by Ola Hallengren, this does not only contain stored procedures for index maintenance but also for database backup and integrity.

Installing it is easy, grab a copy of the installation script and run it. But I would suggest you install it on a new maintenance database and change the following parameters of the install script.

  • USE [master]: Installing it on a separate database maintenance instead of the master makes it easier to uninstall or update.
  • @CreateJobs: I like to set this option to ‘N’ because I don’t want to call the stored procedures directly from the agent but from a T-SQL block inside of a maintenance plan. This looks more consistent so that it doesn’t look like a lack of maintenance plans.
  • The rest of the configuration is quite self-explanatory and personal 😉

At the moment I only use it for index and statistics maintenance so here’s an example on how I like to run it on Dynamics Ax databases.

More information on the parameters of this stored procedure.

Dynamics Ax Management Shell powershell tips

Hi all,

When Dynamics Ax 2012 came out it was shipped with 2 tools AxUtil.exe and the Management shell. In my experience most of the Dynamics Ax developers are already familiar with AxUtil.exe but don’t have much experience in powershell yet. Therefor I decided to write some examples to get you guys going. If you have any questions or a request please leave a comment, I might also add some scripts as I go.

Dynamics Ax custom WCF service with paging support

Hi all,

Lately I’ve been busy developing WCF services to communicate with .NET web applications. All of these web services are custom-made and are using .NET data contracts so that every application uses the same contracts. Due to the high amount of data and performance we had to implement some kind of paging. I had no clue that Ax even has paging support but it does and it does this with properties on the QueryRun objects.

For example purposes I’ve made a service which uses .NET request and response contracts. I prefer this way over X++ data contracts because this is more reusable and flexible on the client side. The code is self-explanatory to me but you can always pose questions of course. 😉

The request contract:

The response contract:

The service implementation:

Calling the service from a .NET application:

Paging on a QueryRun is implement since Ax 2009, more info on paging: http://msdn.microsoft.com/nl-be/library/aa623755(v=ax.50).aspx

I wonder why this isn’t implemented in the AIF services or is it? If anyone knows please leave a comment about it. 😉

Dynamics Ax Implementing an InventDim form control

Hi All,

Yesterday I was struggling a bit with an InventDim form control on a custom-made form. The problem was that the product dimension look ups were returning none or too much results like example 1. While the correct result should look like example 2.

InventDim form control 1 InventDim form control 2

The problem was that I’ve named the item field ServiceItemId instead of ItemId. This is a problem because the class InventDimCtrl_Frm_Lookup looks hard-coded for an ItemId field when you do a look up on an inventory dimension. But there is an exception, the class also looks for a method called itemId. So if you have another field or maybe have 2 item fields on the same table you can implement something like this method to return the correct ItemId.

Dynamics Ax composite queries

Hi all,

Currently I’m working on a new Dynamics Ax 2012 project and for that I’m developing a lot of list pages and forms. For these I had to make multiple menu items that open a list page with different filters, you can do this by setting the menu item query property or calling a class which calls the form with the correct query. So this involves creating a lot of query objects for the same table with only a few extra filters. If only there was a way to inherit queries from each other and there is! 🙂

It’s called composite queries and it’s only useful when you just want to extend your query with range or overriding a method. Also you can only derive one time from a query.

An example:

First I’ve created a base query that filters on  Sales Type with value Sales Order. So I have a query that filters all regular sales orders.

Base query

Next I’m creating a new query without any data sources and I drag my base query to the Composite query node. Then I can add my specific range, such as on Sales Status with value back order.

Open sales order query

That’s it! Now I can create multiple queries such as for delivered or invoiced orders and if I want to apply and extra range for all the queries I only have to change the base query.

source: MSDN

MS SQL Server performance with Dynamics Ax

Hi,

Lately I’m working on some projects who experience a bad performance in Dynamics Ax. This can have multiple causes but one of the most important is maintaining the SQL Server. In my humble opinion every Dynamics Ax developer should have a basic knowledge on how SQL Server works and is maintained because it is the backbone of our beloved ERP software. :-).

This said if terms like rebuilding and reorganizing indexes, updating statistics or recovery model don’t ring a bell these links will be very interesting for you ;-).

 

Dynamics Ax RunBase overriding dialog with a Form

Hi,

Some time ago I’ve found out that you can implement a form into a RunBase dialog, this has the advantage that you can easily use a grid control, etc… or use modified field methods without using controlMethodOverload() method. You can do this by overriding the dialog method and adding the following code.

You can still add fields the normal way by using the addFieldValue() method, these fields will appear next to the embedded form.

This form must have a Tab control and some hardcoded groups, also on the design the property FrameType must be set to None. The groups I’ve created are DialogStartGrp and RightButtonGrp, these are used for positioning fields and query values from code. More groups may be necessary when extending from RunBaseBatch, RunBaseReport, …  The tab control is used for adding a batch tab when extending from RunBaseBatch.

Form example

In the dialogPostRun() method you can get the formRun of the dialog and make calls to the form, for example setting query ranges.

A way to pass data or do callbacks is to get the calling class in the form init.

Dynamics Ax printing logo’s from batch

Hi,

*Edit Microsoft has released a fix for this problem contact support for this*

As all of you know the Image class in Dynamics Ax 4.0 and 2009 can only run on client. This poses a problem when you want to print for example invoices with your company logo on it. Having this found out I went to look for an alternative!

I’ve added this code to the top of the PDFViewer class in the writeBitmap(OutputBitmapField _field, OuputSection _section) method

For the method BLOGWriteBitmapOnServer(OutputBitmapField _field, OuputSection _section) I have copied everything from the writeBitmap and started by replacing the Image object with a System.Drawing.Image object, you can make a company parameter for this file path.

After compiling there are a few errors witch I’ve corrected and ended up with this code.

This could probably been done much cleaner, but it does the job. 🙂

Dynamics Ax Reports with Calibri font

Hi,

A customer of mine asked me to change the font of some reports to Calibri. It all went well until we saved a report as PDF, there was way too much spacing between characters.

After some days of investigating and contact with Microsoft I’ve found out that it worked on a Windows Server 2008 R2 and the Calibri font files were almost double in size. So I replaced the font files with the ones from Windows Server 2008 R2 and the reports are working like a charm. 🙂

Dynamics ax take screenshots from FormControls

Hi all,

Here is a little code snippet for you to take screen shots within a Dynamics Ax client.

This snippets uses the size of your control and the position on your screen to create the screenshot 🙂

Dynamics Ax printing from the AOS

Hello,

This post will be all about printing from printers that are connected on the AOS instead of the client.

First up is installing a printer on the server thats hosts the AOS services. Next is configuring the client and server as shown in the next screenshots:

Client configuration
Client configuration
Server configuration
Server configuration

In the printer setup you should now be able to choose from printers with the prefix “AOS:”

*edit* : If the printer does not show up, try restarting the windows ‘Print Spooler’ service.

Many application object servers today are installed on 64bit operating systems this can cause problems when trying to connect a network printer that is hosted on a 32bit printer server. You might choose to upgrade the operating system of the printer server and face more drivers problems with other 32bit clients or install a secondary 64bit printer server, witch seems overkill.  A better is when the printer is connected directly to the LAN install it on the server thats hosts the AOS services. You can do this by installing the printer local with a TCP/IP port and using the 64bit driver.

Dynamics ax unknown software exception

Hi,

Ever had this error “The exception unknown software exception (0xc0000417) occurred in the application at 0x00a13c18”.

Software error
Software error

Solving it is easy, just erase the .AUC files in the folder:

C:\Documents and Settings\Current user\Local Settings\Application Data

Or for Windows 7 / Windows server 2008 users:

C:\Users\Current user\AppData\Local

Dynamics Ax SQL Trace

Hi there,

here is a simple job to enable SQL tracing for all your users, this quite handy for optimizing queries. (The macro’s for modifying other fields on the UserInfo table can be found on the ClassDeclaration of the SysUserSetup form.)

Make sure that client tracing is enabled in the server configuration. (Only use this in development and testing environments, tracing may affect the AOS performance.)

Server configuration
Server configuration

The results can be found in the Administration module.

SQL trace menu
SQL trace menu