Pass the CostCentre value in the parameter to create the default dimension and fill up other dimension values from cost centre's derived dimensions:
public static DimensionDefault QTQ_CreateDerivedDimension(String20 _costCentre)
{
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttr;
str dimAttrCCValue;
DimensionDefault result;
boolean isDerivedDimension;
dimAttrCCValue = _costCentre;
dimAttr = DimensionAttribute::findByName("CostCentre");//CustParameters::find().QTQ_DimAttName);
dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttr, dimAttrCCValue, false, true);
DimensionAttributeValueDerivedDimensions derivedDim = DimensionAttributeValueDerivedDimensions::findByDimensionAttributeValue(dimAttrValue.DimensionAttribute, dimAttrValue.RecId);
DimensionAttributeValueSetStorage defaultDimStorage = new DimensionAttributeValueSetStorage();
DimensionHierarchy dimHierarchy = DimensionAttributeDerivedDimensions::findDimensionHierarchyForDrivingDimension(DimensionAttribute::find(derivedDim.DimensionAttribute));
DimensionHierarchyLevel dimHierarchyLevel;
DimensionAttributeDerivedDimensions derivedDimensions;
while select RecId, DimensionAttribute from dimHierarchyLevel
where dimHierarchyLevel.DimensionHierarchy == dimHierarchy.RecId
join DerivedDimensionFieldNum from derivedDimensions
where derivedDimensions.DimensionHierarchyLevel == dimHierarchyLevel.RecId
{
DimensionAttributeValueRecId davRecId = derivedDim.(derivedDimensions.DerivedDimensionFieldNum);
DimensionAttributeValue dav = DimensionAttributeValue::find(davRecId);
defaultDimStorage.addItemValues(dimHierarchyLevel.DimensionAttribute, dav.RecId, dav.HashKey);
isDerivedDimension = true;
}
// If there is no derived dimension available then at-least create the default dimension with Cost Centre Value only.
if (!isDerivedDimension)
{
defaultDimStorage.addItem(dimAttrValue);
}
result = defaultDimStorage.save();
return result;
}
No comments:
Post a Comment