Hello Guys,
Here is the post to convert the Default dimension to the ledger dimension.
protected DimensionDynamicAccount getLedgerDimension(mainAccountNum _mainAccountId, RefRecId _defaultDimension)
{
mainAccountNum mainAccountId = _mainAccountId;
MainAccount mainAccount;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionSetSegmentName dimensionSet;
DimensionStorage dimensionStorage;
LedgerAccountContract ledgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract valueContract;
DimensionAttributeValueSetStorage dimStorage;
List valueContracts = new List(Types::Class);
Counter i;
int hierarchyCount;
int hierarchyIdx;
RefRecId recordvalue;
mainAccount = MainAccount::findByMainAccountId(mainAccountId);
recordvalue = DimensionHierarchy::getAccountStructure(mainAccount.RecId,Ledger::current());
hierarchyCount = DimensionHierarchy::getLevelCount(recordvalue);
DimensionSet = DimensionHierarchyLevel::getDimensionHierarchyLevelNames(recordvalue);
for(hierarchyIdx = 1;hierarchyIdx<=hierarchyCount;hierarchyIdx++)
{
if(hierarchyIdx == 1)
{
continue;
}
// _defaultDimension is a RecId that combines all Dimension Values
dimStorage = DimensionAttributeValueSetStorage::find(_defaultDimension);
for (i= 1 ; i<= dimStorage.elements() ; i++)
{
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == DimensionSet[hierarchyIdx])
{
dimensionAttribute = DimensionAttribute::findByLocalizedName(DimensionSet[hierarchyIdx],false, CompanyInfo::find().LanguageId);
if(dimensionAttribute)
{
dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimStorage.getDisplayValueByIndex(i));
if(dimensionAttributeValue)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName(dimensionAttribute.Name) ;
ValueContract.parmValue(dimensionAttributeValue.CachedDisplayValue);
valueContracts.addEnd(ValueContract);
}
}
continue;
}
}
}
LedgerAccountContract.parmMainAccount(mainAccountId);
LedgerAccountContract.parmValues(valueContracts);
dimensionStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
return DimensionAttributeValueCombination::find(dimensionStorage.save()).RecId;
}
No comments:
Post a Comment