Most of the times in our D365 Fin Ops Projects we get a requirement to fetch the dimension values from the Standard Account Structure for value updation in the respective masters through a normal button click event or insert() event handler in Data Entity .
Using the below logic we can easily accomplish our goal of doing the same :-
class CalculateFinancialDimensions
{
public Str1260 calculatefinancialdim(CustTable _custtable)
{
List dimensionAttributeList;
ListEnumerator listEnumerator;
DimensionAttributeSetItem dimAttrSetItem;
DimensionAttribute dimAttr;
DimensionEnumeration dimensionSetId;
DimensionService dimensionService;
DimensionContract dimensionContract;
AccountStructureContract accountStructureContract;
Str1260 dimvalue ;
DefaultDimensionView defaultDimensionViewitem;
dimensionSetId = DimensionCache::getDimensionAttributeSetForLedger();
dimensionService = new dimensionService();
accountStructureContract = new AccountStructureContract();
accountStructureContract.parmName("ABCDim");
dimensionAttributeList = dimensionService.getDimensions(accountStructureContract);
listEnumerator = dimensionAttributeList.getEnumerator();
while (listEnumerator.moveNext())
{
dimensionContract = listEnumerator.current();
// The below select statement will fetch only Active Dimensions
select dimAttr
join RecId from dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
dimAttrSetItem.DimensionAttributeSet == dimensionSetId
&& dimAttr.Name==dimensionContract.parmDimensionName();
select firstonly defaultDimensionViewitem
where defaultDimensionViewitem.DefaultDimension == _custtable.DefaultDimension
&& defaultDimensionViewitem.Name ==dimAttr.Name;
if (defaultDimensionViewitem.RecId)
{
dimvalue += '-'+defaultDimensionViewitem.DisplayValue ;
}
else
{
dimvalue += '-' ;
}
defaultDimensionViewitem.clear();
}
return dimvalue;
}
}
No comments:
Post a Comment