get Dimension Combination Values
Tue Dec 24 2024 13:10:22 GMT+0000 (Coordinated Universal Time)
Saved by @MinaTimo
[ExtensionOf(tableStr(LedgerJournalTrans))]
public final class LedgerJournalTrans_Extension
{
public DimensionDisplayValue getDimensionCombinationValues(LedgerDimensionAccount ledgerdimension)
{
DimensionAttributeLevelValueAllView dimensionAttributeLevelValueAllView;
DimensionAttribute dimensionAttribute;
Set dimensionAttributeProcessed;
LedgerDimensionAccount _ledgerDimension;
str segmentName ;
DimensionDisplayValue segmentDescription;
SysDim segmentValue;
str getDynamicAccountAttributeName(TableNameShort _dimensionAttrViewName)
{
#Dimensions
container cachedResult;
SysModelElement modelElement;
SysDictTable sysDictTable;
DictView dictView;
Label label;
Debug::assert(_dimensionAttrViewName like #DimensionEnabledPrefixWithWildcard);
// Get/cache results of the AOT metadata lookup on the view
cachedResult = DimensionCache::getValue(DimensionCacheScope::DynamicAccountAttributeName, [_dimensionAttrViewName]);
if (cachedResult == conNull())
{
// Find the matching model element and instantiate the AOT metadata definition of the view
select firstOnly AxId, Name from modelElement
where modelElement.ElementType == UtilElementType::Table
&& modelElement.Name == _dimensionAttrViewName;
sysDictTable = new sysDictTable(modelElement.AxId);
Debug::assert(sysDictTable.isView());
// Create an instance of the view and get the singular representation of the entity name as a label ID (do not translate)
dictView = new dictView(modelElement.AxId);
cachedResult = [dictView.singularLabel()];
DimensionCache::insertValue(DimensionCacheScope::DynamicAccountAttributeName, [_dimensionAttrViewName], cachedResult);
}
label = new label();
return label.extractString(conPeek(cachedResult, 1));
}
_ledgerDimension = ledgerdimension;
if (_ledgerDimension)
{
dimensionAttributeProcessed = new Set(extendedTypeId2Type(extendedTypeNum(DimensionAttributeRecId)));
while select DisplayValue, AttributeValueRecId from dimensionAttributeLevelValueAllView
order by dimensionAttributeLevelValueAllView.GroupOrdinal, dimensionAttributeLevelValueAllView.ValueOrdinal
where dimensionAttributeLevelValueAllView.ValueCombinationRecId == _ledgerDimension
join Name, Type, ViewName, RecId from dimensionAttribute
where dimensionAttribute.RecId == dimensionAttributeLevelValueAllView.DimensionAttribute
{
if (!dimensionAttributeProcessed.in(dimensionAttribute.RecId))
{
if (DimensionAttributeType::DynamicAccount == dimensionAttribute.Type)
{
// Use the singular name of the view backing the multi-typed entity
segmentName = getDynamicAccountAttributeName(dimensionAttribute.ViewName);
}
else
{
// Use the name of the attribute directly for all other types (main account, custom list, existing list)
segmentName = dimensionAttribute.localizedName();
}
segmentValue = dimensionAttributeLevelValueAllView.DisplayValue;
if (strLen(segmentDescription) == 0)
{
segmentDescription = DimensionAttributeValue::find(
dimensionAttributeLevelValueAllView.AttributeValueRecId).getName();
}
else
{
segmentDescription += strFmt(" - %1", DimensionAttributeValue::find(
dimensionAttributeLevelValueAllView.AttributeValueRecId).getName());
}
dimensionAttributeProcessed.add(dimensionAttribute.RecId);
}
}
}
return segmentDescription;
}
public display Name OffsetDimensionValue()
{
if(this.OffsetAccountType == LedgerJournalACType::Ledger)
{
return this.getDimensionCombinationValues(this.OffsetLedgerDimension);
}
return '';
//DimensionAttributeValueCombination dimAttrValueComb;
//DimensionStorage dimensionStorage;
//DimensionStorageSegment segment;
//int segmentCount, segmentIndex;
//int hierarchyCount, hierarchyIndex;
//str segmentName, segmentDescription;
//SysDim segmentValue;
//;
//if(this.OffsetLedgerDimension)
//{
// dimAttrValueComb = DimensionAttributeValueCombination::find(this.OffsetLedgerDimension);
// dimensionStorage = DimensionStorage::findById(this.OffsetLedgerDimension);
// hierarchyCount = dimensionStorage.hierarchyCount();
// for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
// {
// segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
// for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
// {
// segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
// if (segment.parmDimensionAttributeValueId() != 0)
// {
// segmentDescription += segment.getName() + '-';
// }
// }
// }
// return strDel(segmentDescription, strLen(segmentDescription), 1);
//}
//else
//return "";
}
public display Name DimensionValue()
{
if(this.AccountType == LedgerJournalACType::Ledger)
{
return this.getDimensionCombinationValues(this.LedgerDimension);
}
return '';
//DimensionAttributeValueCombination dimAttrValueComb;
//DimensionStorage dimensionStorage;
//DimensionStorageSegment segment;
//int segmentCount, segmentIndex;
//int hierarchyCount, hierarchyIndex;
//str segmentName, segmentDescription;
//SysDim segmentValue;
//;
//if(this.LedgerDimension)
//{
// dimAttrValueComb = DimensionAttributeValueCombination::find(this.LedgerDimension);
// dimensionStorage = DimensionStorage::findById(this.LedgerDimension);
// hierarchyCount = dimensionStorage.hierarchyCount();
// for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
// {
// segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
// for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
// {
// segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
// if (segment.parmDimensionAttributeValueId() != 0)
// {
// segmentDescription += segment.getName() + '-';
// }
// }
// }
// return strDel(segmentDescription, strLen(segmentDescription), 1);
//}
//else
//return "";
}
}



Comments