You may have a set of dimension attribute values and you may want to assign these set of values to a main account ledger dimension. The following set of function will help you.
private RecId mergeSegmentValueInDimension(RecId _modifiedDimension,
DimensionValue _businessUnit = '',
DimensionValue _space = '',
DimensionValue _function = '',
DimensionValue _venue = '')
{
//Dimension attributes
#define.businessUnit('BusinessUnit')
#define.space('Space')
#define.functions('TypesofFunctions')
#define.venue('Venue')
RecId newDimension;
DimensionAttributeValue attributeValue;
DimensionAttributeValueSetStorage dimStorage = new DimensionAttributeValueSetStorage();
if (_businessUnit)
{
attributeValue = this.getDimenionAttribute(#businessUnit, _businessUnit);
dimStorage.addItem(attributeValue);
}
if (_space)
{
attributeValue = this.getDimenionAttribute(#space, _space);
dimStorage.addItem(attributeValue);
}
if (_function)
{
attributeValue = this.getDimenionAttribute(#functions, _function);
dimStorage.addItem(attributeValue);
}
if (_venue)
{
attributeValue = this.getDimenionAttribute(#venue, _venue);
dimStorage.addItem(attributeValue);
}
newDimension = DimensionDefaultingService::serviceCreateLedgerDimension(_ledgerDimension, dimStorage.save());
return newDimension; // This will return a new dimension associating main account with segmented value
}
Sub-function-1
private DimensionAttributeValue getDimenionAttribute(Name _dimName,
str _dimValue)
{
DimensionAttribute dimAttribute = DimensionAttribute::findByName(_dimName);
DimensionAttributeValue dimAttributeValue;
if(_dimValue)
{
dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute, _dimValue, true, true);
}
return dimAttributeValue;
}
Cheers !!
Thanks for posting this !
ReplyDelete