Populate LedgerDimension value through code Ax 2012 & D365
public DimensionDynamicAccount getLedgerDimensionId(container _dimensionValue)
{
DimensionStorage dimensionStorage = DimensionStorage::construct(0, LedgerDimensionType::Account);
DimensionAttributeValue dimAttributeValue;
DimensionStorageSegment dimensionStorageSegment;
DimensionHierarchyLevel dimHierarchyLevel;
MainAccount mainAccount;
Recid dimHierarchyId;
Recid mainAccountRecId;
DimensionValue dimensionValue;
container dimensions;
for(int i = 1; i<= conLen(_dimensionValue); i++)
{
try
{
// Rest of dimensions
if(dimensionValue)
{
dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValueNoError(DimensionAttribute::findByName(conPeek(dimensions, i)), dimensionValue, false, true);
if (!dimAttributeValue)
{
// @JAT:DimensionNotFound = The value '%1' of the dimension '%2' does not exist.
throw error(strFmt("DimensionNotFound", dimensionValue, conPeek(dimensions, i)));
}
dimensionStorageSegment = DimensionStorageSegment::constructFromValue(dimAttributeValue.CachedDisplayValue, dimAttributeValue);
dimensionStorage.setSegment(i, dimensionStorageSegment);
}
else
{
dimensionStorageSegment = DimensionStorageSegment::emptySegment();
dimensionStorage.setSegment(i, dimensionStorageSegment);
}
}
catch
{
return 0;
}
}
return dimensionStorage.save();
}
No comments:
Post a Comment