Finally...in code, how to retrieve a dimension value from a default dimension and a dimension name:
public str getDimensionValueByName(DimensionDefault _dimension, str _dimensionName)
{
DimensionAttributeValueSetStorage dimStorage;
Counter i;
str result;
dimStorage = DimensionAttributeValueSetStorage::find(_dimension);
for(i = 1; i <= dimStorage.elements(); i++)
{
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == _dimensionName)
{
result = dimStorage.getDisplayValueByIndex(i);
break;
}
}
return result;
}
How to get or create a default dimension:
public DimensionDefault getOrSetDefaultDimension()
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
str dimValue;
container conAttr = [d1Name, d2Name, d3Name];
container conValue = [d1Value, d2Value, d3Value];
for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
dimValue = conPeek(conValue,i);
if (dimValue != "")
{
// The last parameter is "true". A dimensionAttributeValue record will be created if not found.
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
}
result = valueSetStorage.save();
return result;
}