Thursday, March 6, 2014

Mandelbrot set with AX and other fun jobs

copy and paste the code into a Job and enjoy :)

Check out this thread for more fun: Art Of Creation – Dynamics AX Blog


(THX to Lasse from EG)
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)
          {
            break;
          }
          n++;
        }
        if( N > StrLen(Chars))
        {
          n = StrLen(Chars);
        }
        printLine += subStr(chars, N, 1);
        x++;
      }
      print printLine;
      y++;
    }
    pause;
}

Thursday, January 2, 2014

Import Vendor Invoices with AIF LedgerGeneralJournalService

One way of posting vendor invoices is simply posting credit to a vendor via a General Journal. From a business process point of view you might want to do this if you do not have Purchase Order Documents to post the invoice. Usually this happens in case of expense bills...such as office materials.

If you choose the AIF LedgerGeneralJournalService be aware of the following Problem:

Certain fields in the table LedgerJournalTrans do not get populated when using the Account Type "Vendor"
EG:
- the vendors posting profile is missing
- no Terms of Payments
- the due date does not get calculated


This happens because code on the form is triggered when you select the vendor account manually. The above described fields usually get populated by the LedgerJournalEngine Class.

Fix:
To fix this problem you have to modify the service axd Class. But caution! If you simply call the Standard LedgerJournalEngine Class, the AIF produces an Error. Here is my first approach:

AxdLedgerGeneralJournal
public void updateNow()
{
    (.. std code ..)
    
    // -->
    LedgerJournalTrans      ledgerJournalTrans;
    LedgerJournalEngine_DailyAif   ledgerJournalEngine = new LedgerJournalEngine_DailyAif();
    // <-- data-blogger-escaped---="" data-blogger-escaped-..="" data-blogger-escaped-code="" data-blogger-escaped-std="">
    ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans();
    switch (ledgerJournalTrans.AccountType)
    {
        case LedgerJournalACType::Vend:
            ledgerJournalEngine.accountModified(ledgerJournalTrans);
            ledgerJournalEngine.initFromVendTable(ledgerJournalTrans);
            break;
    }
    ledgerJournalTrans.update();

    (.. std code ..)
}

any inbound message will now result into the following Error: The request failed with the following error:
Exception of type 'Microsoft.Dynamics.Ax.Xpp.InvalidRemoteCallException' was thrown

Debugging with VS surfaced that the use of the FormRun parameter in the constructor resulted into an error. You need to create a couple of new classes based on LedgerJournalEngine and LedgerJournalEngine_Daily. Simply get rid of the parameter in method new().

I finally got everything to work with the following code:

AxdLedgerGeneralJournal
public void updateNow()
{
    #macrolib.LedgerAIF
    SysGlobalCache          cache = classfactory.globalCache();
    LedgerJournalTable      ledgerJournalTable;
    LedgerJournalInclTax    ledgerJournalInclTax;
    // -->
    LedgerJournalTrans      ledgerJournalTrans;
    //  LedgerJournalEngine_DailyAif is a new class based on LedgerJournalEngine
    LedgerJournalEngine_DailyAif   ledgerJournalEngine = new LedgerJournalEngine_DailyAif();
    // <--

    super();

    ledgerJournalTable = axLedgerJournalTable.ledgerJournalTable();
    ledgerJournalInclTax = LedgerJournalTable::find(ledgerJournalTable.JournalNum).LedgerJournalInclTax;
    [ledgerJournalTable.JournalTotalDebit,
        ledgerJournalTable.JournalTotalCredit,
        ledgerJournalTable.JournalTotalOffsetBalance] = LedgerJournalTable::journalBalanceMST(ledgerJournalTable.JournalNum,
                                                            false,
                                                            ledgerJournalInclTax,
                                                            false);
    ledgerJournalTable.JournalBalance = ledgerJournalTable.JournalTotalDebit - ledgerJournalTable.JournalTotalCredit;
    ledgerJournalTable.update();

    // -->
    ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans();
    switch (ledgerJournalTrans.AccountType)
    {
        case LedgerJournalACType::Vend:
            ledgerJournalEngine.accountModified(ledgerJournalTrans);
            ledgerJournalEngine.initFromVendTable(ledgerJournalTrans);
            break;
    }
    ledgerJournalTrans.update();
    // <--

   (.. std code ..)
}

If you want to reproduce this scenario:
- get the latest AX2012 vm (refresh 4 with CU7)
- create a new inbound port for the AIF service (simply use the file system adapter...)
- use the following xml



  
ussi http://schemas.microsoft.com/dynamics/2008/01/services/GeneralJournalService/create
ussi Detail GenJrn General Journal Vend 1007.00 ussi USD US_SI_000007 US_SI_000007 1.0000000000 Ledger ussi 500110-003-022-00000001-Application Development 500110 BusinessUnit 003 Department 022 Project 00000001 ServiceLine Application Development 2013-12-26 No Po Invoice

Further thoughts:

- Alternatively you could use the service LedgerPurchaseInvoiceService, this will create an Invoice Register (but in my experience they are less frequently used than the Ledger Journals / Invoice Journals)
- In order to submit a invoice number with the GeneralJournalService you need to add the field invoice!


hope this helps
-k