onsdag den 16. november 2011

Project accounting 3 - Dynamics AX 2012 - indirect cost / burden

I was tasked with getting an indirect cost setup to work in project accounting 3, but encountered some problems.

Having read the excellent set up guide at http://www.dynamicscare.com/blog/index.php/applying-indirect-burden-costs-to-project-ax-2012-labor-actuals/comment-page-1#comment-3324  (Thanks to Merrie Cosby for this) I proceeded to make the set up according to this guide, but failed to get it working. :(

After some debugging I found that there is an error in the calculation of indirect costs when you run Dynamics AX 2012 in other languages than english.

When setting up Compounding Rules the “Base amount” that you chose, is actually hardcoded in the logic that makes the calculations.

The error can be found in

class PSAIndirectCostCalculation
method calculate:

#define.BaseComponent(‘Base amount’)

This could be corrected so that the define is


And the check for the BaseComponent

if (_sId == #BaseComponent)

is changed to

if (_sId == strFmt(#BaseComponent))

Then at least it works in danish language. :0)

onsdag den 12. oktober 2011

Dynamics AX 2012 - how to delete a layer

With the advent of model management in Dynamics AX 2012, Microsoft has gotten rid of the ax.aod files which in previous versions of DAX constituted the layers.
In DAX 2012 adjustments for the meta data model and code are stored in the modelstore in the database.

In previous version deleting a layer containing adjustments to the standard application consisted of delete the ax.aod file and synchronizing and compiling.

How is this done in DAX 2012 ?

The answer is a command-line tool called AxUtil.

To delete e.g. the usr-layer in the application do the following:

1) Shut down all AOS-servers but one (applicable only if you have more than one AOS running).
2) Go to command line interface on the server where the last AOS is running.
3) Go to the folder where DAX's management utilities are placed, e.g.
    C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities
4) Run the Axutil like this:
    Axutil delete /layer: /db:

    To delete the usr-layer in the MicrosoftDynamicsAx database:
    Axutil delete /layer:usr /db:MicrosoftDynamicsAx

    Below an example is shown:

5) Restart the AOS
6) Start the DAX client.
7) In the process of starting up, DAX will detect that something has happened with the modelstore, and prompt you with:

    Choose the action appropriate for your situation.
8) Start the remaining AOSes.

tirsdag den 13. september 2011

Dynamics AX 2012 SSRS report - "Report has no design."

I just helped a colleague fix a little problem in Dynamics AX 2012.

He was going through a tutorial to make a (SSRS) report in Dynamics AX 2012.
He had designed the report complete with a dataset getting SalesTable data from AX, and had deployed it to the Report Server.
He had also made a menu item for the report and put that in the menu in AX.

However when he clicked the menu item AX failed to run the report giving the error
"Report has no design."

We poked around using a breakpoint in the Info class, to find that the AX class failing was ReportRun.
The method in ReportRun we ended up in expected to receive a designname.
However as nearly all AX reports are gone and replaced with SSRS reports in Dynamics AX 2012, this lead me to believe that something was up with the menuitem.

We examined the output menu item to find that the ObjectType property was set to "Report" which is a remnant of the old AX reporting system.
We corrected this property to SSRSReport, and voila.
Ax now ran the report with no problems.

fredag den 26. august 2011

RunBaseBatch inheritance and saving last values chosen in a query

Today I found a little hack that is useful.
I have a (super) class extending RunBaseBatch.
This class build a query on the fly.
This class also implements a dialog, which of course have a select button, so you can input search ranges for the query the class uses.

I have a second (sub) class extending the first (super) class.
Of course the sub-class also uses a query object.

The problem was that when the super class and the sub class instatiates a query on the fly the query is nameless, and therefor execution of the dialog for the query ranges, resulted in the savelast values for the query to become messed up, so that when you ran the sub-class you would get the query ranges from the super-class and vice versa.

A simple solution exists to this problem:
When you instatiate the query object in the and then the queryRun object, you can do:


giving the queryRun object the name of the object instatiated using the super- or subclass.
This seems to keep the query ranges sys last values separate for the two classes.

tirsdag den 17. maj 2011

Programmatically accessing a dimension field

The following snippet can be used (in a form) to programmatically toggle mandatory mode on a dimension field (in this case department).

tirsdag den 3. maj 2011

Axapta & Dynamics ax 4.0 & 2009: Formatting real-controls i AX reports using x++ code PART II

A classic problem with ERP-systems running in multinational enterprises is the formatting of amount fields in a report.

One aspect of this is that the different currencies in which the different national companies of an enterprise operates can vary a lot with regards to number of digits in the amount.

E.g. the exchange rate between a danish kroner and an indonesian rupiah is (at time of writing):

1 DKK - 1524,75 IDR.

This would for an amount of 1 million danish kroner yield an converted amount of 1,524,750,000.75 IDR. An amount of the size can result in the Dynamics AX core returning

Today I was asked by a customer, to come up with a prototype for user enabling the setting of widths of fields on a report

The class that formats Real fields can be found here:

Recursively refreshing any calling forms with ONE method

In the project module you can create item requirements for a project (which are basically items you sell via the project). At a customer site, a customized table and form, has been added to the item requirements forms, so the customer is able to set up item specifications for each item requirement, consisting of records with different kinds of data which describes the item.

A class bas been made to import a .csv-file to an set of intermediate tables where data which forms the basis of item requirements and item specifications are stored.

On the item requirements form, you can call a form showing the contents of the intermediate tables and from this form you can then (via a menuitem button) call a class that facilitates population of the item requirements AND item specifications from the itermediate table. When populating the item requirements table based on the intermediate table, you deleted the contents of the intermediate table.

So you have the

Project form calling the
Item Requirements form
calling the Intermediate table form,

from where you perform the population of item requirements and specification.

How do you refresh the Item requirements form, and the itermediate table form to show that data has been "moved" from the intermediate form to the item requirements form WITH ONE METHOD CALL.

On the class performing the population i added a method that recursively examines the args object to see if the caller is a form, and then call the executequery method on the form datasource:

void doCallingFormsRefresh(Args _args)
    FormDataSource fds;
    Args prevLevelArgs;

    // refresh calling form
    if (_args.caller() && _args.dataset() && _args.record().isFormDataSource())
        // Previous level of args (args from caller's caller)
        prevLevelArgs = _args.caller().args();

        fds = _args.record().dataSource();

        if (prevLevelArgs && prevLevelArgs.record().TableId != tablenum(ProjTable) && prevLevelArgs.record().isFormDataSource())

Notice that the Projtable form is NOT refreshed.
This way I avoided all the tedious call back methods on the forms, that is normally done.


mandag den 4. april 2011

Methods of opening a browser

Mental note to self: Ways of programmatically opening a browser with a webpage in x++:


This will open the standard browser.


This specifically opens internetexplorer. The last method can also be used for starting up 3rd party applications from Axapta.

A quick way of dumping records of a table in an xml-file.

A quick way of of dumping table records into a xml-file is to use the kernel method xml, which is present on all instances of a tablebuffer. However, the xml produced by this method is NOT well-formed.

Three problems exists:
  • No header info for the xml-document is written
  • No root node is written
  • The data within tags are not html escaped
When the xml-method is called a call to the GLOBAL class method XMLString method is made.
With a little adjustment to this method we can make the XML data output wellformed.

But first you must add this method to the GLOBAL class:

public static str escapeHTMLChars(str _in)
    int x;
    str out;
        if ((char2num(_in,x) < 32) && (char2num(_in,x) > 126))
            out += '&#'+num2str(char2num(_in,x),0,0,0,0)+';';
            out += substr(_in,x,1);
    return out;

And now back to the global::XMLString method.
The last code block in the method is a big switch case construct handling all data types in x++. In the string handler section:

case Types::RSTRING:
case Types::VARSTRING:
case Types::STRING:     r += legalXMLString(value);

Insert this code just before the break-statement:

r = global::escapeHTMLChars(r);

To call the method mentioned above.
So the code will look like this:

case Types::RSTRING:
case Types::VARSTRING:
case Types::STRING:
                    r += legalXMLString(value);
                    r = global::escapeHTMLChars(r);

Now it is possible to write code that:
  1. Writes an xml-header.
  2. Writes a root node tag.
  3. Iterates a table and calls the xml-method on the tablenbuffer. 
  4. Write the end for the root node tag.
static void Job45(Args _args)
    query q;
    QueryRun qr;
    AsciiIo f;

    f = new AsciiIo('\\\\axdev2\\e$\\CIT Files\\jas\\mcfly.xml','w');
    if (!f)
        throw error("Argh ! File can not be created.");
    // Write root node
    q = new Query();
    // Get customer no. 0215

    qr = new QueryRun(q);
    while (qr.next()) {
    f = null;
    // Show xml-file in browser
    winapi::shellExecute('\\\\axdev2\\e$\\CIT Files\\jas\\mcfly.xml');