Wednesday, 19 February 2014

Top 10 issues discovered from Dynamics AX Code Review

Check the following link related to Dynamics Ax2012   X++ coding point of view

http://blogs.msdn.com/b/axinthefield/archive/2014/02/18/top-10-issues-discovered-in-the-dynamics-ax-code-review.aspx

Friday, 7 February 2014

X++ Debugging Tips and Tricks

I found a useful link for debugging x++.Here i am going to share this link

http://blogs.msdn.com/b/mfp/archive/2013/09/23/x-debugging-tips-and-tricks-part-1.aspx

How Create Customize Look up for Financial Dimension in Ax2012

Following lookup help for dimension filtration according to enum value over here
DimType  is customized filed which contain  Department, CostCenter, Project, Account  and BusinessUnit.
Select any one option then use following code of lookup for filter                                                                

public void lookup()
{

    Query query = new Query();
    QueryBuildDataSource                queryBuildDataSource;
    QueryBuildRange                         qbrForAccount;
    SysTableLookup                           sysTableLookup;
    DimType                                        dimType;
    DimensionAttribute                        dimensionAttribute;
    DimensionAttributeDirCategory       dimAttributeDirCategory;
    ;

    dimType = str2enum(dimType,FilterGroup_Type.valueStr());

    switch(dimType)
    {
        case  DimType::Department:

            sysTableLookup = SysTableLookup::newParameters(tableNum(OMOperatingUnit),this,true);
            sysTableLookup.parmUseLookupValue(false);
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, OMOperatingUnitNumber));
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, Name));
            queryBuildDataSource = query.addDataSource(tableNum(OMOperatingUnit));
            queryBuildDataSource.addSortField(fieldnum(OMOperatingUnit,OMOperatingUnitNumber));
            queryBuildDataSource.addRange(fieldNum(OMOperatingUnit,      OMOperatingUnitType)).value(int2str(any2int(OMOperatingUnitType::OMDepartment)));
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
            break;

        case  DimType::BusinessUnit:

            sysTableLookup = SysTableLookup::newParameters(tableNum(OMOperatingUnit),this,true);
            sysTableLookup.parmUseLookupValue(false);
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, OMOperatingUnitNumber));
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, Name));
            queryBuildDataSource = query.addDataSource(tableNum(OMOperatingUnit));
            queryBuildDataSource.addSortField(fieldnum(OMOperatingUnit,OMOperatingUnitNumber));
            queryBuildDataSource.addRange(fieldNum(OMOperatingUnit, OMOperatingUnitType)).value(int2str(any2int(OMOperatingUnitType::OMBusinessUnit)));
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
            break;

        case  DimType::CostCenter:


            sysTableLookup = SysTableLookup::newParameters(tableNum(OMOperatingUnit),this,true);
            sysTableLookup.parmUseLookupValue(false);
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, OMOperatingUnitNumber));
            sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit, Name));
            queryBuildDataSource = query.addDataSource(tableNum(OMOperatingUnit));
            queryBuildDataSource.addSortField(fieldnum(OMOperatingUnit,OMOperatingUnitNumber));
            queryBuildDataSource.addRange(fieldNum(OMOperatingUnit, OMOperatingUnitType)).value(int2str(any2int(OMOperatingUnitType::OMCostCenter)));
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
            break;
        case  DimType::Project:

            dimensionAttribute = DimensionAttribute::findByName("Project");
            if (dimensionAttribute.Type == DimensionAttributeType::CustomList)
            {
            select firstonly DirCategory from dimAttributeDirCategory where dimAttributeDirCategory.DimensionAttribute == dimensionAttribute.RecId;
            sysTableLookup = SysTableLookup::newParameters(tableNum(DimensionFinancialTag), this,true);
            sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Value));
            sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Description));
            query = new Query();
            query.addDataSource(tableNum(DimensionFinancialTag)).addRange(fieldNum(DimensionFinancialTag, FinancialTagCategory)).value(queryValue(dimAttributeDirCategory.DirCategory));
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
            }
            break;


        case DimType::Account:

            sysTableLookup = SysTableLookup::newParameters(tableNum(MainAccount),this,true);
            sysTableLookup.parmUseLookupValue(false);
            sysTableLookup.addLookupfield(fieldNum(MainAccount, MainAccountId));
            sysTableLookup.addLookupMethod(tableMethodStr(MainAccount, localizedName));
            sysTableLookup.addLookupfield(fieldNum(MainAccount, Type));
            queryBuildDataSource = query.addDataSource(tableNum(MainAccount));
            qbrForAccount = queryBuildDataSource.addRange(fieldNum(MainAccount,LedgerChartOfAccounts));
            qbrForAccount.value(queryValue(Ledger::current()));
            queryBuildDataSource.addSortField(fieldnum(MainAccount,MainAccountId));
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
            break;

     
}