Announcing new book: Microsoft Dynamics AX 2012 R2 Services

March 4, 2014 at 23:50
filed under Dynamics AX
Tagged , , , ,

Hi everyone!

I’m very happy to announce Microsoft Dynamics AX 2012 R2 Services, published by Packt Publishing and authored by Kenny and myself. It is the successor of Microsoft Dynamics AX 2012 Services which was very well received. Based on the feedback you had, we started working on an update in September 2013. We have gone through all existing content, updated and improved it, and added a lot of new content. We are really happy with the result and are excited to hear your reactions.

We are working hard on the book at the moment, the expected release date is May 2014 but you can already pre-order it.
Read on if you want to know what to expect and have a chance to win a copy of Microsoft Dynamics AX 2012 R2 Services.

Microsoft Dynamics AX 2012 R2 Services RAW Microsoft Dynamics AX 2012 R2 Services RAW

What to expect

We have challenged ourself to create a book that we ourself would want to read. Because of that, instead of only providing a small update, we have also added a lot of new content. To reader of the first book, it can be summarized as follows:

For new readers, we will make a chapter freely available on the Packt Publishing article network so you get a glimpse of what is in the book (I will update this page when the article is online).


To celebrate this new release, we are giving away a number of copies of the Microsoft Dynamics AX 2012 R2 Services book:

That’s 14 copies of the book and a PackLib subscription. Here’s what you need to do to win:

A big thanks to Packt Publishing for sponsoring this giveaway, and good luck to you all. The contest will close on the 21st of March 2014 and I will contact you if you win (so use your real email address when commenting).

Please check the shipping info on the website of Packt Publishing to see whether they ship to you region before entering this contest and also read their terms and conditions. Some kind of disclaimer: Keep in mind that this contest is intended to a fun experience (both for me and you). Understand that I can not make any commitments regarding the delivery of the prizes. Oh, and if I know you personally you will not win a prize :-). You can both comment and retweet by the way. Comments will have to be approved by me (so it might take some time to show up) but that’s only to avoid spam.

Good luck and I hope you like the book!

Update March 27: Contest closed, I will contact the lucky winners shortly (and update this post again).
Update: All codes have been given away, thanks for your comments!


RSS / trackback

  1. Klaas Deforche

    To format you code use the following syntax:
    [cc lang=XPP]// your code goes here[/cc]
    It wiill look like this:

    // your code goes here
  2. pradeep Itnal

    static void firstorsecondprize(Args _args)
        TmpBankTotal  banktotal;
            banktotal.AccountId = '123';
            banktotal.Balance = 2345;
           throw error('operation aborated');
  3. pradeep Itnal

    static void PSI_SalesTax_per_POLine(Args _args)
      TaxTmpWorkTransForm     taxTmpWorkTransForm;
      PurchTotals             purchTotals;
      TaxPurch                 taxPurch;

      purchTotals = PurchTotals::newPurchTable(PurchTable::find(‘PO0000004CA’)); //purchase order number in find method.
      taxPurch =;

      taxTmpWorkTransForm = TaxTmpWorkTransForm::construct();
     taxTmpWorkTransForm.updateTaxShowTaxesSourceSingleLine(tableNum(PurchLine), PurchLine::find(‘PO0000004CA’,2,false).RecId, true);
  4. Muhammad Haroon

    static void SelectWinner(Args _args)
        GiveAwayParticipants    giveAwayParticipants;

        giveAwayParticipants = GiveAwayParticipants::randomFind();

        giveAwayParticipants.winner = NoYes::Yes;

        info(strfmt("Winner %1",;

    Outcome: Winner: Klaas Deforche

    Come on Klass, you do not need book. Give chance to others. :p

  5. Manu

    static void funfunfun(Args _args)
        FormRun formRun;
        Args args = new Args();

        formRun = ClassFactory.formRunClass(args);
  6. Lasse

    Low tech – quick hack = fun :)

    static void totallyuseless(Args _args)
        int rows = 40, cols = 80;
        int maxIter = 256;
        real fVRct = -2.5, fVRctImg=-1.00,fMagLevel=0.05,fCImg=0,fC,fZ,fZImg,fZSqr,fZImgSqr;
        int X = 1,Y = 1,N = 0;
        str chars = "▓▒▒░¤ghijklmnoprstuvwxyz123456▒890!#╧%/()=@£$?{[]}*ABCDE█GHIJ█LMNOPQRSTUVXY@";
        str printLine;
        window cols, rows at 50,20;
        Y = 1;
        while(Y < rows)
          fcImg = fVRctImg + Y * fMagLevel;
          printLine = "";
          X = 1;
          while(X < cols)
            fC = fVRct + X * fMagLevel;
            fZ = fC;
            fZImg  = fCImg;

            N = 0;
            while(N < maxIter)
              fZSqr = fZ * fZ;
              fZImgSqr = fZImg  * fZImg;
              fZImg = 2 * fZ * fZImg + fCImg;
              fZ = fZSqr - fZImgSqr + fC;
              if(fZImgSqr+fZImgSqr > 4)
            if( N > StrLen(Chars))
              n = StrLen(Chars);
            printLine += subStr(chars, N, 1);
          print printLine;

    If things look a bit strange, you might have to adjust the “chars” string a bit to make it look right! :)

  7. Robesz

    Lasse! You killed my joke :-)

    static void StarWarsIVcrawl_withRandomStars(Args _args)
        container   textCont;
        int         i, printWindowHeight = 21, printWindowWidth = 77, firstLines = 5;
        str         line;
        Random      random = new Random();
        textCont = ["A long time ago, in a galaxy far, far away....",
                    "It is a period of civil war. Rebel",
                    "spaceships, striking from a hidden",
                    "base, have won their first victory",
                    "against the evil Galactic Empire.",
                    "During the battle, Rebel spies managed",
                    "to steal secret plans to the Empire's",
                    "ultimate weapon, the Death Star, an",
                    "armored space station with enough",
                    "power to destroy an entire planet.",
                    "Pursued by the Empire's sinister agents,",
                    "Princess Leia races home aboard her",
                    "starship, custodian of the stolen plans",
                    "that can save her people and restore",
                    "freedom to the galaxy..."];
            line = "";
            if(i <= firstLines || i > (firstLines + conLen(textCont)))
                    line += strRep(#space, 1 + random.nextInt() MOD printWindowWidth/4) + #AllFilesName;
                while (strLen(line) < printWindowWidth);
                line = conPeek(textCont, i - firstLines);
                line = StrRep(#space, real2int((printWindowWidth - strLen(line))/2)) + line;

        while (i < (conLen(textCont) + printWindowHeight + firstLines));
  8. FH-Inway


    nice job with the first book, would love to get my hands on the updated R2 version.

    Best regards


  9. Jo

    info(conPeek(new HeapCheck().createAContainer(), 4));

    Niet getest in 2012! :-)

  10. Klaas Deforche

    Lol okay, didn’t know that. I tested it and it says “buffer buffer buffer buffer ” in AX 2012 so it seems they changed it.

  11. Jo

    It took them long enough!

  12. ET

    static void DictAllTables(Args _args)
    ExtendedTypeId dictTypeId;
    DictTable dictTable;
    Dictionary dictionary;
    counter cnt;
    TableId tableId;

    dictionary = new Dictionary();
    tableId = dictionary.tableNext(0);

    info(“Name;Field count;Index count;Table group;Has RecId Index;Has Surrogate key;Is SQL;Cache lookup”);
    for (tableId = dictionary.tableNext(0); tableId; tableId = dictionary.tableNext(tableId))
    dictTable = new dictTable(tableId);

    info(strfmt(“%1;%2;%3;%4;%5;%6;%7;%8”,, dictTable.fieldCnt(), dictTable.indexCnt(), dictTable.tableGroup(), dictTable.hasRecidIdx(), dictTable.hasSurrogateKey(),
    dictTable.isSql(), dictTable.cacheLookup()));

  13. ET

    Should have read the comment on code formatting :-)

    static void DictAllTables(Args _args)
        ExtendedTypeId      dictTypeId;
        DictTable           dictTable;
        Dictionary          dictionary;
        counter             cnt;
        TableId             tableId;

        dictionary = new Dictionary();
        tableId = dictionary.tableNext(0);

        info("Name;Field count;Index count;Table group;Has RecId Index;Has Surrogate key;Is SQL;Cache lookup");
        for (tableId = dictionary.tableNext(0); tableId; tableId = dictionary.tableNext(tableId))
            dictTable = new dictTable(tableId);

            info(strfmt("%1;%2;%3;%4;%5;%6;%7;%8",, dictTable.fieldCnt(), dictTable.indexCnt(), dictTable.tableGroup(), dictTable.hasRecidIdx(), dictTable.hasSurrogateKey(),
                dictTable.isSql(), dictTable.cacheLookup()));
  14. Kim

    // haha! you guys are awesome :)

    static void KlaasRocks(Args _args)
    container tcontainer;
    str tline;
    int row;
    tcontainer = [
    “K:::::::K K:::::Kl:::::l”,
    “K:::::::K K:::::Kl:::::l”,
    “K:::::::K K::::::Kl:::::l”,
    “KK::::::K K:::::KKK l::::l aaaaaaaaaaaaa ssssssssss ssssssssss”,
    “K:::::K K:::::K l::::l a::::::::::::a ss::::::::::s ss::::::::::s”,
    “K::::::K:::::K l::::l aaaaaaaaa:::::ass:::::::::::::s ss:::::::::::::s”,
    “K:::::::::::K l::::l a::::as::::::ssss:::::ss::::::ssss:::::s”,
    “K:::::::::::K l::::l aaaaaaa:::::a s:::::s ssssss s:::::s ssssss”,
    “K::::::K:::::K l::::l aa::::::::::::a s::::::s s::::::s”,
    “K:::::K K:::::K l::::l a::::aaaa::::::a s::::::s s::::::s”,
    “KK::::::K K:::::KKK l::::l a::::a a:::::assssss s:::::s ssssss s:::::s”,
    “K:::::::K K::::::Kl::::::la::::a a:::::as:::::ssss::::::ss:::::ssss::::::s”,
    “K:::::::K K:::::Kl::::::la:::::aaaa::::::as::::::::::::::s s::::::::::::::s”,
    “K:::::::K K:::::Kl::::::l a::::::::::aa:::as:::::::::::ss s:::::::::::ss”,
    “KKKKKKKKK KKKKKKKllllllll aaaaaaaaaa aaaa sssssssssss sssssssssss”
    tline = ”;
    tline = conPeek(tcontainer, row );
    while (row < (conLen(tcontainer)));
    tline = conPeek(tcontainer, 1 );

  15. Mike Frank

    variation on the theme brought up by Kim ;-)

    static void KlaasRocksDotNet(Args _args)
        System.Drawing.Bitmap bitmap;
        System.Drawing.Graphics graphics;
        System.Drawing.Font font;
        System.Drawing.SizeF sizeF;
        System.Drawing.Size size;

        System.Drawing.Imaging.ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat::get_Bmp();
        FileName imageFileName = System.IO.Path::Combine(WinAPI::getTempPath(), 'AxImage.bmp');

        str text = "Klaaaas rocks";
        str fontName = "Verdana";
        int fontSize = 25;
        boolean bold = true;

        str formatLastCLRException()
            System.Exception clrException = CLRInterop::getLastException();
            System.Type type;
            str message;

            if (!CLRInterop::isNull(clrException))
                type = clrException.GetType();
                if (CLRInterop::getAnyTypeForObject(type.get_FullName()) != 'System.Reflection.TargetInvocationException')
                    message = CLRInterop::getAnyTypeForObject(clrException.get_Message());
                clrException = clrException.get_InnerException();
                while (!CLRInterop::isNull(clrException))
                    if (message)
                        message += '\t';
                    message += CLRInterop::getAnyTypeForObject(clrException.get_Message());
                    clrException = clrException.get_InnerException();
            return message;

            bitmap = new System.Drawing.Bitmap(10, 10);
            graphics = System.Drawing.Graphics::FromImage(bitmap);

            font = new System.Drawing.Font(fontName, fontSize, bold ? System.Drawing.FontStyle::Bold : System.Drawing.FontStyle::Regular);
            sizeF = graphics.MeasureString(text, font);
            size = sizeF.ToSize();
            bitmap = new System.Drawing.Bitmap(size.get_Width(), size.get_Height());
            graphics = System.Drawing.Graphics::FromImage(bitmap);

            graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color::get_White()), new System.Drawing.Rectangle(0, 0, size.get_Width(), size.get_Height()));
            graphics.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color::get_Red()), new System.Drawing.PointF(0, 0));


            bitmap.Save(imageFileName, imageFormat);

            throw error(formatLastCLRException());
  16. Kim

    Nice :)
    I hope this thread will continue and somebody makes good use of the WinAPI::beep method!

  17. Klaas Deforche

    I was waiting for the same thing, hehe. I was trying to make it work yesterday using console.beep() or beep() but failed. Didn’t know there was a beep function in WINAPI, cool! Mario theme playing now…. :D

  18. Edward

    Hi Klaas,
    Thumbs up! Keep up the good work :-)

    static void Job1(Args _args)
    //within previous version(s) the InventDimSearch is used
    //boolean isDimInventBatchIdActive(ItemId _itemId)
    //    InventTable     inventTable = InventTable::find(_itemId);
    //    return new InventDimSearch().find(inventTable.DimGroupId, fieldnum(InventDim,InventBatchId)).dimActive();
    //within AX2012 the EcoResTrackingDimGroupSetup is used
    boolean isDimInventBatchIdActive(ItemId _itemId)
        EcoResTrackingDimGroupSetup     trackingDimGroupSetup;
        InventTable                     inventTable;
        inventTable           = InventTable::find(_itemId);
        trackingDimGroupSetup = EcoResTrackingDimGroupSetup::newDimensionGroup(inventTable.trackingDimensionGroup());

        return trackingDimGroupSetup && trackingDimGroupSetup.getFieldSetup(fieldNum(InventDim,InventBatchId)).isActive();
    //test the method  
        InventTable inventTableSearch;
        while select inventTableSearch
  19. Dominic

    Trying my luck here.


  20. Jimmy

    Great posts and comments as always! :)



    static void JustAForm4Fun(Args _args)
        Form                   form;
        FormRun             formRun;
        Args                    args;
        FormBuildDesign         formBuildDesign;
        FormBuildControl        formBuildControl;
        FormBuildTabControl     formBuildTabControl;
        FormBuildTabPageControl formBuildTabPageControl;
        FormBuildStringControl  formBuildStringControl;
        FormBuildButtonControl  formBuildButtonControl;
        FormBuildGroupControl   formBuildGroupControl;
        FormBuildDatasource     formBuildDatasource;
        FormBuildStringControl  formString;
        FormButtonControl       buttonCtrl;

        form = new Form();
        formBuildDesign = form.addDesign('design');
        formBuildDesign.caption('How building a form can be done quick and dirty...');

        formBuildTabControl = formBuildDesign.addControl(FormControlType::Tab, 'Tab');

        formBuildTabPageControl = formBuildTabControl.addControl(FormControlType::TabPage, 'TabPage');

        formBuildGroupControl  = formBuildTabPageControl.addControl(FormControlType::Group, 'Group');
        formBuildStringControl = formBuildGroupControl.addControl(FormControlType::String, 'StringTextbox');
        formBuildStringControl.text('Thank you for the blogposts and hopefully a copy of the Services ebook :-) ');

        formBuildButtonControl = formBuildGroupControl.addControl(FormControlType::Button, 'MyButton');
        formBuildButtonControl.text('PRESS ME...AND EXPECT NOTHING');

        args    = new Args();

        formRun = new FormRun(args);
  21. dfga

    Congrats on your new book! Can’t wait to get it, just make it happen! LOL :)

  22. JantjeLeiden

    Good initiative, would love the ebook.
    Anything about using REST in there ?

  23. Klaas Deforche

    Yes, REST is mentioned on a few occasions, for example when using the OData query services and when consuming a web service. Don’t expect a lot of REST content though, it’s just mentioned when needed.