Skip to main content

Get Financial Dimensions attached to Funding Source of Project Contracts in Excel | AX 2012

I just came across a scenario where I had to import the Projects as WIPs from legacy system. For that I imported Projects and Project Contracts in the System, partly using DIXF and partly using excel add-in. During the import, I figured out that Funding Rules Allocation were not updated, so I had to write a custom job to updated that. Later, I saw that Financial Dimensions on Projects were imported correctly but those on Funding Source were empty, so I wrote following job to see which dimensions are currently attached to the Project Contract. I am sharing it with you all so somebody might not need to reinvent the wheel. Happy DAXing! ☺

static void getProjContractDims(Args _args)
{
    InventTable         inventTable;
    SysExcelApplication application;
    SysExcelWorkbooks   workbooks;
    SysExcelWorkbook    workbook;
    SysExcelWorksheets  worksheets;
    SysExcelWorksheet   worksheet;
    SysExcelCells       cells;
    SysExcelCell        cell;
    int                 row,col;
    ProjFundingSource   projFundingSource;
    DimensionAttributeValueSetItem  dimensionSet;
   
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
   
    cells = worksheet.cells();
    cells.range('A:A').numberFormat('@');
    cell = cells.item(1,1);
    cell.value("ProjContractId");
    cell = cells.item(1,2);
    cell.value("Dimension");
    cell = cells.item(1,3);
    cell.value("BusinessLine");
    cell = cells.item(1,4);
    cell.value("Customer");
    cell = cells.item(1,5);
    cell.value("Department");
    cell = cells.item(1,6);
    cell.value("ItemGroup");
    cell = cells.item(1,7);
    cell.value("Project");
    cell = cells.item(1,8);
    cell.value("Region");
    row = 1;   
   
    while select ContractId, DefaultDimension from projFundingSource    {
        info(projFundingSource.ContractId);
        row++;
        cell = cells.item(row, 1);
        cell.value(projFundingSource.ContractId);
        cell = cells.item(row, 2);
        cell.value(projFundingSource.DefaultDimension);
       
        while select DimensionAttributeValueSet, DimensionAttributeValue, DisplayValue from dimensionSet
            where dimensionSet.DimensionAttributeValueSet == projFundingSource.DefaultDimension
        {
                      switch(DimensionAttribute::find((DimensionAttributeValue::find(dimensionSet.DimensionAttributeValue).DimensionAttribute)).Name)
            {
                case 'BusinessLine':
                    cell = cells.item(row, 3);
                    cell.value(dimensionSet.DisplayValue);
                    break;
                case 'Customer':
                    cell = cells.item(row, 4);
                    cell.value(dimensionSet.DisplayValue);
                    break;
                case 'Department':
                    cell = cells.item(row, 5);
                    cell.value(dimensionSet.DisplayValue);
                    break;
                case 'ItemGroup':
                    cell = cells.item(row, 6);
                    cell.value(dimensionSet.DisplayValue);
                    break;
                case 'Project':
                    cell = cells.item(row, 7);
                    cell.value(dimensionSet.DisplayValue);
                    break;
                case 'Region':
                    cell = cells.item(row, 8);
                    cell.value(dimensionSet.DisplayValue);
            }
        }
    }
    application.visible(true);
   

}

Comments

Popular posts from this blog

Get Position and Department of an employee | AX 2012

A simple job to get position/designation and department of an employee using employee id: static void WorkerPositionDepartment(Args _args) {     HcmWorker                       hcmWorker;     HcmPositionWorkerAssignment     hcmPositionWorkerAssignment;     OMOperatingUnit                 oMOperatingUnit;     HcmPositionDetail               hcmPositionDetail;     HcmJob                          hcmJob;     HcmPosition             ...

Creating BOM journal using code AX 2012

courtesy: http://www.andesoft.net/creating-bom-journal-using-x-code-ax-2009-ax-2012/ https://community.dynamics.com/ax/f/33/t/96262.aspx http://learnax.blogspot.com/2010/01/x-code-to-create-and-post-inventory.html static void createBomJournal_working(Args _args) {     InventJournalTable      journalTable;     InventJournalTrans      journalTrans;     InventJournalTableData  journalTableData;     InventJournalTransData  journalTransData;     InventTable             inventTable;     InventDim               inventDim;     Counter                 cnt;     InventJournalCheckPost  journalCheckPost = new InventJournalCheckPost();     InventTransId           inventTransId, inventTransIdFather;     InventBat...

Auto create job card journal in Production | AX 2012

Multiple journals are created in the production process. When the order is started route card journal and picking list journal are auto created. But system does not create job card journal automatically. It requires a small customization. Following method can be called when the production order is started with the production order id passed as the parameter. /// <summary> /// This method auto creates Job Card Journal and its lines against selected production order. /// </summary> private void autoCreateJobCardJournal(ProdId _prodId) {     ProdJournalTable    prodJournalTable;     ProdRoute           prodRoute;     ProdRouteJob        prodRouteJob;     ProdJournalRoute    prodJournalRoute;     ProdParametersDim   prodParametersDim;     int   ...