Showing posts with label financial dimensions in ax 2012. Show all posts
Showing posts with label financial dimensions in ax 2012. Show all posts

Friday, 12 May 2017

Update Financial dimensions for all customers using X++

static void DefaultFinancialDim(Args _args)
{
    DimensionAttributeValue dimAttrBUValue,dimAtrrCCValue,dimAtrrDepValue,dimAttrIGValue,dimAtrrProjValue;
    DimensionAttribute dimAttrBU,dimAtrrCC,dimAtrrDep,dimAttrIG,dimAtrrProj;
    DimensionAttributeValueSetStorage davss;
    RecId defaultDimension;
    CustTable custTable;

    while select forUpdate custTable
    {
        if(custTable.AccountNum)
        {
            davss = DimensionAttributeValueSetStorage::find(CustTable::find(custTable.AccountNum).DefaultDimension);

            dimAttrBU = DimensionAttribute::findByName('BusinessUnit');
            dimAtrrCC = DimensionAttribute::findByName('CostCenter');
            dimAtrrDep = DimensionAttribute::findByName('Department');
            dimAttrIG = DimensionAttribute::findByName('ItemGroup');
            dimAtrrProj = DimensionAttribute::findByName('Project');

            dimAttrBUValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttrBU, "003", false, true);
            dimAtrrCCValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrCC, "009", false, true);
            dimAtrrDepValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrDep, "024", false, true);
            dimAttrIGValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttrIG, "AudioRM", false, true);
            dimAtrrProjValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrProj, "000006", false, true);

            if(dimAttrBUValue || dimAtrrCCValue ||dimAtrrDepValue || dimAttrIGValue || dimAtrrProjValue)
            {
                davss.addItem(dimAttrBUValue);
                davss.addItem(dimAtrrCCValue);
                davss.addItem(dimAtrrDepValue);
                davss.addItem(dimAttrIGValue);
                davss.addItem(dimAtrrProjValue);
                //custTable = custTable::find(custTable.AccountNum, true);

                ttsBegin;
                custTable.DefaultDimension = davss.save();

                custTable.update();
                ttsCommit;

                info(custTable.AccountNum);
            }
        }
    }

}

How to update financial dimensions for master data using x++ code in Ax 2012


Customers:

To update financial dimensions to all legal entities.

static void updateCustomerDimensions(Args _args)
{
    CustTable       custTable;
  
    Struct struct;// = new Struct();
    container           ledgerDimension,com;
    DimensionDefault    DimensionDefault;
    CompanyInfo         companyInfo;

    while select companyInfo where companyInfo.DataArea !="DAT"
    {
        struct = new struct();
        com = conNull();
        changeCompany(companyInfo.DataArea)
        {
            ledgerDimension =conNull();
            com = conIns(com,1,companyInfo.DataArea);
          
            struct.add('LegalEntity',companyInfo.DataArea);
            ledgerDimension += struct.fields();
            ledgerDimension += struct.fieldName(1);
            ledgerDimension += struct.valueIndex(1);


            DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
            //Customers
          
            while select forUpdate crossCompany:com * from custTable
            {
                if(custTable.RecId)
                {
                    ttsBegin;
                    custTable.DefaultDimension = DimensionDefault;
                    custTable.update();
                    info(strFmt("Customer %1 dimension updated -- %2",custTable.AccountNum,custTable.dataAreaId));
                    ttsCommit;
                }
            }
        }
    }


}

Fixed asset:

static void updateAssetDimensions(Args _args)
{
    AssetTable      assetTable;
    AssetBook       assetBook;
    Struct struct;// = new Struct();
    container           ledgerDimension,com;
    DimensionDefault    DimensionDefault;
    CompanyInfo         companyInfo;

    while select companyInfo where companyInfo.DataArea !="DAT"
    {
        struct = new struct();
        com = conNull();
        changeCompany(companyInfo.DataArea)
        {
            ledgerDimension =conNull();
            com = conIns(com,1,companyInfo.DataArea);

            struct.add('LegalEntity',companyInfo.DataArea);
            ledgerDimension += struct.fields();
            ledgerDimension += struct.fieldName(1);
            ledgerDimension += struct.valueIndex(1);


            DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
            //Vendors

            while select forUpdate crossCompany:com * from assetBook
            {
                if(assetBook.RecId)
                {
                    ttsBegin;
                    assetBook.DefaultDimension = DimensionDefault;
                    assetBook.update();
                    info(strFmt("Asset %1 dimension updated -- %2",assetBook.assetid,assetBook.dataAreaId));
                    ttsCommit;
                }
            }
        }
    }


}

Update financial dimensions for master data:

static void testUpdateCustomerDimensions(Args _args)
{
    CustTable           custTable;
    Struct              struct;
    container           ledgerDimension,com;
    DimensionDefault    DimensionDefault,custDimensionDefault;
    CompanyInfo         companyInfo;

    DimensionAttributeValueSetStorage    dimStorage;
    Counter                              i;
    str                                  BusUnit,CCUnit,Dep,IG;
    ProjId                               projId;
    container                            conDefaultdim;

    struct = new struct();
    com = conNull();

    ledgerDimension =conNull();

    select forUpdate custTable where custTable.AccountNum =="US-011";

    custDimensionDefault = custTable.DefaultDimension;

    dimStorage = DimensionAttributeValueSetStorage::find(custDimensionDefault); //default dimension value

    for (i=1 ; i<= dimStorage.elements() ; i++)
    {
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "BusinessUnit")
        {
            BusUnit = dimStorage.getDisplayValueByIndex(i);
        }
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "CostCenter")
        {
            CCUnit = dimStorage.getDisplayValueByIndex(i);
        }
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Department")
        {
            Dep = dimStorage.getDisplayValueByIndex(i);
        }
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "ItemGroup")
        {
            IG = dimStorage.getDisplayValueByIndex(i);
        }


        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Project")
        {
            projId = "000003";//dimStorage.getDisplayValueByIndex(i);
        }

    }
    //projId = "000002";

    conDefaultdim = [5,'BusinessUnit',BusUnit,'CostCenter',CCUnit,'Department',Dep,'ItemGroup',IG,'Project',projId];

    DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(conDefaultdim);

    if(custTable.RecId)
    {
        ttsBegin;
        custTable.DefaultDimension = DimensionDefault;
        custTable.update();
        info(strFmt("Customer %1 dimension updated -- %2",custTable.AccountNum,custTable.dataAreaId));
        ttsCommit;
    }


}

http://axgenius.blogspot.in/2017/05/how-to-update-financial-dimensions-for.html