Wednesday, June 13, 2012

Create a new record in dimensionAttributeValueCombination, by AX2012 code

refRecId getLedgerDimension(container _c)
{
    DimensionServiceProvider    DimensionServiceProvider = new DimensionServiceProvider();
    LedgerAccountContract       LedgerAccountContract = new LedgerAccountContract();
    DimensionAttributeValueContract ValueContract;
    List                            ListValueContract = new List(Types::Class);

    dimensionAttributeValueCombination  dimensionAttributeValueCombination;

    DimensionStorage                    dimStorage;

    str         _ledgerAccount = conPeek(_c, #Account);
    str         _department = conPeek(_c, #Department);
    str         _location = conPeek(_c, #Location);
    str         _region = conPeek(_c, #Region);
    str         _zone = conPeek(_c, #Zone);
    str         _company = conPeek(_c, #Company);

    if (_department)
    {
        ValueContract = new DimensionAttributeValueContract();
        ValueContract.parmName('Department') ;
        ValueContract.parmValue(_department);
        ListValueContract.addEnd(ValueContract);
    }

    if (_location)
    {
        ValueContract = new DimensionAttributeValueContract();
        ValueContract.parmName('Location') ;
        ValueContract.parmValue(_location);
        ListValueContract.addEnd(ValueContract);
    }

    if (_region)
    {
        ValueContract = new DimensionAttributeValueContract();
        ValueContract.parmName('Region') ;
        ValueContract.parmValue(_region);
        ListValueContract.addEnd(ValueContract);
    }

    if (_zone)
    {
        ValueContract = new DimensionAttributeValueContract();
        ValueContract.parmName('Zone') ;
        ValueContract.parmValue(_zone);
        ListValueContract.addEnd(ValueContract);
    }

    if (_company)
    {
        ValueContract = new DimensionAttributeValueContract();
        ValueContract.parmName('Company') ;
        ValueContract.parmValue(_company);
        ListValueContract.addEnd(ValueContract);
    }

    LedgerAccountContract.parmMainAccount(_ledgerAccount);
    LedgerAccountContract.parmValues(ListValueContract);

    dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);

    dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());

    return dimensionAttributeValueCombination.RecId;
}

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...