onsdag den 29. marts 2017

Dynamics ax 2012 SSRS reports RDP Changing Query

I have used a bit of time this morning trying to figure out how to change the query in an RDP based SSRS report.

I needed to change the report from using a query JmgPaySpecification to using the query JmgPaySpecificationExt instead.

I started out by changing the


attribute in the classdeclaration of the RDP class and compiling it.

Then I went to Visual Studio, opened the report and doing a rebuild on it to get it refreshed in the AOT.

However that didn't seem to change anything, and doing a find on the SSRS-report searching all nodes and searching for JmgPaySpecification revealed:

So doing the above changed nothing.

The solution is, to go into Visual Studio opening the report:

1. Go to Datasets and highlight the Dataset
2. Change the Data Source Type from Report Data Provider type to Query.
    This clears the Query setup.
3. Change the Data source Type back to Report Data Provider.
4. Go to the Query field and choose the (new) query and the choose the fields. (In my case the Query     JmgPaySpecificationExt).
5. Build.
6. Leave VS (not saving the report model).

Going back to the AOT and doing refresh will reveal that the SSRS report has been rebuilt.
Repeating the find on the SSRS-report searching all nodes and searching for JmgPaySpecification revealed:

Which is what I wanted.

Also remember to deploy the new SSRS-report to the reporting server by Right-clicking on the report in the AOT and choosing Deploy Element.

mandag den 2. januar 2017

Quickly setting up what the status bar will show for your user.

When documenting test or setup it is advantageous to show as many values in the status bar as possible (especially the AOS name and company accounts id and maybe date and time), to be able to show in screen dumps what environment you are using.

Here is a quick little job for setting up ALL fields to be shown in the status bar.

Dynamics AX 2009:

static void Job130(Args _args)
    #LOCALMACRO.FLAG_StatusLineHelpText             (1 << 0) #ENDMACRO
    #LOCALMACRO.FLAG_StatuslineDatabase             (1 << 1) #ENDMACRO
    #LOCALMACRO.FLAG_StatuslineWatch                (1 << 2) #ENDMACRO
    #LOCALMACRO.FLAG_StatuslineNumLock              (1 << 3) #ENDMACRO
    #LOCALMACRO.FLAG_StatuslineCapsLock             (1 << 4) #ENDMACRO
    #LOCALMACRO.FLAG_StatuslineActivity             (1 << 5) #ENDMACRO
    #LOCALMACRO.FLAG_StatuslineSystemDate           (1 << 6) #ENDMACRO
    #LOCALMACRO.FLAG_StatusLineShowUtilLayer        (1 << 7) #ENDMACRO
    #LOCALMACRO.FLAG_StatusLineShowCurrency         (1 << 8) #ENDMACRO
    #LOCALMACRO.FLAG_StatusLineShowUser             (1 << 9) #ENDMACRO
    #LOCALMACRO.FLAG_StatusLineShowCustom           (1 << 10) #ENDMACRO
    #LOCALMACRO.FLAG_StatusLineShowAlertStatus      (1 << 11) #ENDMACRO
    #LOCALMACRO.FLAG_StatusLine_unknown             (1 << 12) #ENDMACRO
    #LOCALMACRO.FLAG_StatusLineAOSName              (1 << 13) #ENDMACRO

    UserInfo        u;

    select firstonly forupdate u
        where u.id == curuserid();
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLineHelptext; // Bit 0
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatuslineDatabase; // Bit 1
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatuslineWatch; // Bit 2
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatuslineNumLock; // Bit 3
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatuslineCapsLock; // Bit 4
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatuslineActivity; // Bit 5
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatuslineSystemDate; // Bit 6
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLineShowUtilLayer; // Bit 7
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLineShowCurrency; // Bit 8
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLineShowUser; // Bit 9
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLineShowCustom; // Bit 10
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLineShowAlertStatus; // Bit 11
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLine_unknown; // Bit 12
    u.statuslineInfo = u.statuslineInfo | #FLAG_StatusLineAOSName; // Bit 13

Dynamics AX 2012 version will follow.

mandag den 14. november 2016

Dynamics AX 2009 Ressources graphics

Here's how to get graphics stored in AOT as a ressource onto a report in Dynamics AX 2009.

Do a display method with:

display Bitmap  companyLogo()
    return SysResource::getResourceNodeData(SysResource::getResourceNode(identifierstr('zabel_JPG')));

where zabel_jpg is the graphics file stored in ressources in the AOT.

Drag the method onto the design.

torsdag den 6. oktober 2016

Toggling visibility of fields in a Grid in then preview Pane of a ListPage form using code

Tasked with hiding a specific field on the salesLine table in the sales order forms depending on the value of a field on SalesTable I searched for methods and came across:


I agree with the method of finding the field on the datasource of the formpart
however a better method of making the field invisible is to reference


instead of actually having to reference the form control.

This will make the field visible/invisble anywhere in the form that the field of the datasource is used.

In my case it was done like this:

private void toggleintraCodeReturn()
    PartList    pl;
    int pCount,partdsCount;
    FormRun part;
    boolean shown;
    FormDataSource pfds;

    FormDataSource  fds,partfds;
    shown = this.currentSalesTable().CustMaterial == NoYes::Yes;
    if (this.currentSalesTable().isFormDataSource())
        fds = this.currentSalesTable().dataSource();
        pl = new PartList(fds.formRun());
        if (pl)
            // Getting parts for form
                part = pl.getPartById(pCount);
                if (part.name() == identifierStr('SalesTableListPagePreviewPane'))
                    // Getting datasources for part form
                        fds = part.dataSource(partdsCount);
                        // Here we got hold of sales lines data source
                        if (fds.table() == tableNum(SalesLine))

fredag den 16. september 2016

Dynamics AX and project quotations in in .docx format

Just finished an assignment making a tool for Dynamics AX 2012R2 for creating project quotations in word, using AX data.
The customer is an ETO company manufacturing production lines for slaugtherhouses.

The tool should create a quotation file word document (.docx) using a word template (.dotx) prepared in a certain language. This would allow the customer to design the layout of the document in a easy and familiar way.

The spec required the quotation to include

Budgets with detailed information for each sub project of a main project.
Budgets summarized for each sub project of a main project.
Scope of supply, which contains short technical descriptions of the included units on the production lines (sub projects)
Technical descriptions - a section of the document containing listing (only once for each unit/sub project) complete descriptions with pictures of each included unit

The algorithm in short is this:

Now the challenge was that for most itemids in the item forecast of the projects, there exists a word document (product sheet) containing detailed product facts. Each product sheet contains four sections

a title
a short description
a middle long description (containing a picture of the unit)
a long description (containing a picture of the unit)

Depending on the user input in the dialog when running the tool, the tool should extract one or more of the sections of the product sheet (mentioned above), and include the extracted sections in the quotation word document.

I have used a 3rd party component called Aspose. This component allows you to work with several document formats, reading, editing and creating documents, without having to have the software normally used to work with the document format installed. That is, Dynamics AX can actually work with the documents SERVER SIDE without having to have Office installed on the AOS.

So I made a .dll in c# that the x++ code uses for the work to be done with the word files, and the x++ code is made so that we can replace the query with other queries if necessary.

The template setup contains features for

searching the word file for bookmarks for insertion of values
searching the word file for fields for insertion of values

The values that AX can insert are categorized as so:

Ordinary table.field values
Ordinary table.method values
A table of values (that can be Axtable fields og Axtable table methods)
A word document section (an extracted section of a separate word document)
A fixed text

The template can be setup by the user combining the bookmarks/fields to search for in the word document and the type of value to be inserted when found.

When a new template is created, the tool can examine the word template, and extract all bookmarks/fields (discover) so that the user has a basic setup he can use to map the ax fields/methods etc up against which bookmarks/fields should be substituted.
Again Aspose is used to do this.

We have used Aspose in other Dynamics AX projects:

Axapta version 3.0 - where we used Aspose to ensure that print out of .pdf-files was always the same page orientation (potrait) in connection with a AX report output )

Dynamics AX 2012 R3  creating .pdf-files for customer visits with user editable forms to send out to sales personnel - ensuring they can open the file and gather input regardless of hardware platform and being online or not.

Aspose is a good tool when you have to make applications that create or edit .pdf-.files, excel-files, word-files. It can even do imaging and OCR, though I haven't worked with those areas.

torsdag den 9. april 2015

Dynamics AX 2012 AOT add-in copying field list to clip board

Before Dynamics AX 2012 and the new editor which makes things a bit more Visual Studio like, we had some features in the AOT, that are gone now but I miss.

I *might* have rambled and raved about this before (http://gotdax.blogspot.dk/2012/03/dynamics-ax-2012-annoyances-for-old.html) ;-).

E.g. I miss the ability to mark all fields on a table in the AOT and simply copy them to code.
In the olds days this could be done by simply marking the fields in AOT and dragging them to the editor window.

I needed this and got fed up with having to type the field names my self so I made a little class with the main method:

public static void main(Args _args)

    DictTable   dt;
    DictField   df;
    int f,start,end;
    Set s;
    SetEnumerator se;
    int tableno;
    TextBuffer txtb = new TextBuffer();
    str fieldNameList;
    str tableName;
    TreeNode treeNode;
    str searchFor = 'Path: '+#TablesPath+#AOTDelimiter;

    if (SysContextMenu::startedFrom(_args))   // started from SysContextMenu
        treeNode = _args.parmObject().first();
    else    // started with a button (or from a menu!)
    if (_args.dataset() == tablenum(UtilElements))
        treeNode = xUtilElements::getNodeInTree(_args.record());
    if (strScan(treeNode.toString(),#TablesPath,1,1024))
        start = strScan(treeNode.toString(),searchFor,1,1024)+strLen(searchFor);
        if (strScan(treeNode.toString(),'\\Fields',1,1024))
            end = strScan(treeNode.toString(),#FIELDS,1,1024);
            end = strScan(treeNode.toString(),' Layer: ',1,1024);
        tablename = subStr(treeNode.toString(),start,end-start);
        s = new Set(Types::String);

        if (tableName)
            tableno = tableName2id(tableName);
            dt = new DictTable(tableno);
            if (dt)
                    df = new DictField(tableno,dt.fieldCnt2Id(f));
                    if (!df.isSystem())
                se = s.getEnumerator();
                while (se.moveNext())
                    fieldNameList += (fieldNameList ? "\n" : "") + se.current();

                info("Field names copied to clipboard.");

And dragged the class to the Menu Items \ Action to create the action menu item:

I then added this menu item to the SysContextMenu:

Then I can go to a table in the AOT and right click and choose add-ins / Copy field names to clipboard.

and afterwards just paste into word or excel:

I think its useful for making documentation.

You can download a private project from:


onsdag den 25. marts 2015

Calculating easter sunday in different ways

Once a long time ago I found an interesting document on the inter web, describing different calendar systems.

From that I made a php-class for my website that can calculate easter sunday in the gregorian calendar. Then it is easy to calculate the rest of the danish holidays as they are offset according to easter sunday (except of course those that have a fixed date).

I translated that class in to x++.

You can find it here:


Today I got talking with a colleague about calculating easter sunday so he mentioned that he had also made a version of the calculation:


So of course - being a bit nerdy - we just *had* to check if the routines arrived at the same result. So we came up with:

static void EasterTest(Args _args)
    Yr x;
    date easter(Yr yr) // Påskedag / påske søndag
        int g,c,h,i,j,l;
        int easterday, eastermonth;
        g = yr mod 19;
        // Gregorian Calendar
        c = real2int(rounddown(yr / 100,1));
        h = (c - roundDown(c/4,1)-rounddown(((8*c)+13)/25,1)+(19*g)+15) mod 30;
        i = h - rounddown(h/28,1)*(1- rounddown(29 / (h+1),1) * rounddown((21-g) / 11,1));
        j = (yr + (rounddown(yr/4,1))+i+2 - c + (rounddown(c/4,1))) mod 7;
        l = i - j;
        easterday = 3+rounddown((l+40)/44,1);
        return mkdate(l+28-31*rounddown(easterday / 4,1), easterday, yr);
    date dateOfEaster(Yr y)
        int a = y mod 19;
        int b = y div 100;
        int c = y mod 100;
        int d = b div 4;
        int e = b mod 4;
        int f = (b+8) div 25;
        int g = (b-f+1) div 3;
        int h = (19*a+b-d-g+15) mod 30;
        int i = c div 4;
        int k = c mod 4;
        int l = (32+2*e+2*i-h-k) mod 7;
        int m = (a+11*h+22*l) div 451;
        int n = (h+l-7*m+114) div 31;
        int p = (h+l-7*m+114) mod 31;
        return mkdate(p+1,n,y);
    for (x = 1900; x <= 2154; x++)
        if (dateOfEaster(x) != easter(x))
            info(strFmt('E1=%1 E2=%2', dateOfEaster(x), easter(x)));

And the routines calculated the same dates for easter sunday.

We stopped ourselves when discussing if we should implement a tick-couting-measurement to see if my colleagues routine was faster than mine. :-)

But I think mine is slower as it uses several function calls and not pure arithmetic.