Sunday, 3 December 2017

How to update Default Financial Dimension in AX 2012 using X++ code

Hi Friends,

The following job will get a DimensionAttributeValueSet record ID base on the a set of dimension values.

static void BSRK_DIM_Make_DefaultFinancialDimXPP(Args _args)
    DimensionAttributeValue                 dimAtrrDepValue,dimAtrrLegalEntityValue,dimAtrrWorkerValue;
    DimensionAttribute                      dimAtrrDep,dimAtrrLegalEntity,dimAtrrWorker;
    DimensionAttributeValueSetStorage       davss;
    HcmPositionDefaultDimension             positionDefaultDimension;
    DefaultDimensionView                    defaultDimensionViewLE,defaultDimensionViewWorker;
    str                                     companyLegalEntity,departmentNo;
    HcmPersonnelNumberId                    personnelNumberId;
    positionDefaultDimension = HcmPositionDefaultDimension::findByPositionLegalEntity(5637198579,CompanyInfo::find().RecId);
    select DisplayValue from defaultDimensionViewWorker
        where defaultDimensionViewWorker.DefaultDimension == positionDefaultDimension.DefaultDimension
            && == 'Department';
    select DisplayValue from defaultDimensionViewLE
        where defaultDimensionViewLE.DefaultDimension == positionDefaultDimension.DefaultDimension
            && == 'LegalEntity';
    departmentNo        = defaultDimensionViewWorker.DisplayValue;
    companyLegalEntity  = defaultDimensionViewLE.DisplayValue;
    personnelNumberId   = HcmWorker::find(5637203085).PersonnelNumber;
    davss = DimensionAttributeValueSetStorage::find(positionDefaultDimension.DefaultDimension);

    dimAtrrDep          = DimensionAttribute::findByName('Department');
    dimAtrrLegalEntity  = DimensionAttribute::findByName('LegalEntity');
    dimAtrrWorker       = DimensionAttribute::findByName('Worker');

    dimAtrrDepValue         = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrDep,departmentNo,false,true);
    dimAtrrLegalEntityValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrLegalEntity,companyLegalEntity,false,true);
    dimAtrrWorkerValue      = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrWorker,personnelNumberId,false,true);

    if(dimAtrrDepValue || dimAtrrLegalEntityValue || dimAtrrWorkerValue)
        positionDefaultDimension = HcmPositionDefaultDimension::findByPositionLegalEntity(5637198579,CompanyInfo::find().RecId,true);
        positionDefaultDimension.DefaultDimension =;


Tuesday, 5 May 2015

Exception has been thrown by the target of an invocation in AX 2012

Original post:
During Purchase orders posting some times we will get this error. "Exception has been thrown by the target of an invocation"
1-22-2013 5-01-34 PM

The fix is simple – for every user, go to “Tools > Options > Development > General” and UNCHECK the “Execute business operations in CIL” box.

1-22-2013 5-27-57 PM


Thursday, 9 April 2015

Debugging in Dynamics AX 2012


Some times we are unable to find from where the error is raising.
Let suppose when you click one of the button on a Dynamics AX form, you are getting info log with error message. Now you have task to find the root cause of this error message.

With Dynamics AX it is very simple to find out from where this error is originating.
Pre-requisite to start is, you should have access to the AOT and Dynamics AX Debugger is installed and configured.
Open AOT
Find Class called Info
Open 'Add' method in Info class
Set a breakpoint in 'Add' method
Now run the Form from where you are getting error
Click the button which gives the error
When the help of breakpoint set, while executing system will land you in dynamics AX debugger
With the help of Dynamics AX Debugger tools, you can find out the execution stack and point out the logic which is throwing error.

Original post here:

Tuesday, 24 March 2015

X++ Code for Item on hand quantity in AX 2012 Retail

static void OnHandQtyRetailsSiva(Args _args)
    RetailStoreId       store = 'ANNARBO';
    ItemId                itemid = '0001';
    InventQty           postedQty;

    InventDimParm          inventDimParmCrit;
    InventSumDateDim    inventSumDateDim;
    InventDim                 inventDim;
    InventDim                 inventDimloc;

    inventDim.InventLocationId  = store;
    inventDim.InventSiteId        = 'CENTRAL';

    inventDimloc = InventDim::findOrCreate(inventDim);

    inventSumDateDim = inventSumDateDim::newParameters(systemDateGet(), itemId, inventDimloc, inventDimParmCrit);

    postedQty = InventSumDateDim.postedQty();
    info(strFmt('%1', postedQty));

X++ Code for Item on hand quantity in AX 2012

static void OnHandQtyDimensionWise(Args _args)
    InventOnhand            inventOnhand;
    InventDim               inventDim;
    InventDimParm           inventDimParm;
    ItemId                  itemId = '0001';
    InventQty               inventQty;

    inventDim.InventSiteId = 'CENTRAL';
    inventDim.InventLocationId = 'ANNARBO';

    inventDim = InventDim::findOrCreate(inventDim);

    inventOnhand = inventOnhand::newParameters(itemId,inventDim,inventDimParm);
    inventQty = inventOnhand.availPhysical();
    info(strFmt('Available: %1 ',inventQty));

Text file creation in AX 2012

Performing File IO with the TextIo Class [AX 2012]

From MSDN 

X++ code performs file input and output (IO) by using the TextIo class. TextIo uses Unicode.

The following X++ job code sample creates a file and writes to it. Next the code reads from the file, and prints every record to the Infolog.
The use of the FileIOPermission class is also illustrated. FileIoPermission is used to assert that the current method has the authority to call another method that checks for such authority. For more information, see Code Access Security.
static void Job_File_IO_TextIo_Write_Read(Args _args)
    TextIo txIoRead,
    FileIOPermission fioPermission;
    container containFromRead;
    int xx,
    str sTempPath,
        sFileName = "Test_File_IO.txt",
    // Get the temporary path.
    sTempPath = WINAPI::getTempPath();
    info("File is at: " + sTempPath + sFileName);

    // Assert permission.
    fioPermission = new FileIOPermission
        (sTempPath + sFileName ,"RW");
    // If the test file already exists, delete it.
    if (WINAPI::fileExists(sFileName))
        WINAPI::deleteFile(sTempPath + sFileName);
    // Open a test file for writing.
    // "W" mode overwrites existing content, or creates the file.
    txIoWrite = new TextIo( sTempPath + sFileName ,"W");

    // Write records to the file.
    txIoWrite.write("Hello        World.");
    txIoWrite.write("The sky is blue.");
    txIoWrite.write("// EOFile");

    // Close the test file.
    txIoWrite = null;

    // Open the same file for reading.
    txIoRead = new TextIo(sTempPath + sFileName ,"R");
    // Read the entire file into a container.
    containFromRead =;

    // Loop through the container of file records.
    while (containFromRead)
        sOneRecord = "";
        iConLength = conLen(containFromRead);
        // Loop through the token in the current record.
        for (xx=1; xx <= iConLength; xx++)
            if (xx > 1) sOneRecord += " ";
            sOneRecord += conPeek(containFromRead ,xx);

        // Read the next record from the container.
        containFromRead =;

    // Close the test file.
    txIoRead = null;
    // Delete the test file.
    WINAPI::deleteFile(sTempPath + sFileName);

    // revertAssert is not really necessary here,
    // because the job (or method) is ending.
  1. Output:
  2. File is at: C:\DOCUME~1\myalias\LOCALS~1\Temp\Test_File_IO.txt
  3. Hello World.
  4. The sky is blue.
  5. // EOFile

Monday, 26 January 2015

Extracting layer wise Objects through Code in AX 2012 or AX 2009

static void getLayers(Args _args)


TreeNode treeNode;

XInfo xInfo;



treeNode = xInfo.findNode(#FormsPath);

treeNode = treeNode.AOTfirstChild();



if (treeNode.applObjectlayer() == utilEntryLevel::usr)





treeNode = treeNode.AOTnextSibling();


Sunday, 25 January 2015

AX 2012 R3 CU8 Installation

Hi Friends,
Finally i installed the AX 2012 R3 CU8 with Slipstream installation.
see my Kernel and Application versions are same. 6.3.1000.309.