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

Run SSRS report using x++ code | AX 2012

This post describes how to run an SSRS report through x++ code and passing report parameters as well. Its a simple code and comments are added for further ease in code understanding! public static void runSSRSReport() {     SrsReportRunController controller;             controller = new SrsReportRunController();     controller.parmLoadFromSysLastValue(false);      // write report name and its design in quotes that you want to run     controller.parmReportName("ReportName.DesignName");      // set additional, optional properties like setting landscape to true     controller.parmReportContract().parmPrintSettings().landscape(true);          // set print destination screen/printer/file etc.     controller.parmReportContract().parmPrintSettings().printMediumType (SRSPrintMediumType::S...

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...