LedgerDimension from individual DefaultDimension

Hi everybody,

have a problem setting up LedgerDimension from an individual dimension of Cust’s DefaultDimension.

I’ll try to explain better by posting my code

CustTable   custTable;
int         i;
DimensionValue         dimValue;
    
LedgerDimensionAccount  ledgerAccount;
    
DimensionAttributeValueSetStorage   dimStorage;
    
custTable = custTable::find(#AccountNum#);

dimStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);

for (i= 1 ; i<= dimStorage.elements() ; i++)
{
    if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == #SearchedDimension#)
    {
        dimValue = dimStorage.getDisplayValueByIndex(i);
        break;
    }
}

ledgerAccount = DimensionDefaultingService::ServiceCreateLedgerDimension(_ledgerDimensionOrig, #NewDefaultDimension#);

What I am trying to achieve is to merge my _ledgerDimensionOrig with the value of the found individual dimension (dimValue). But I am stuck on how to create the #NewDefaultDimension# starting from that individual dimension.

Hope I explained mysef,

Thanks for any replies!

Joshua

Hi all,

at the end I found out the solution.

I use this function below that returns the DimensionDefault created from just my individual extracted _dimValue from previous code.

private DimensionDefault createDimensionDefault(str _dimValue)
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;

    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;

    container               conAttr = ["DIMVALUE"];
    container               conValue = [_dimValue];
    str                     dimValue;

    for (i = 1; i <= conLen(conAttr); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }

        dimValue = conPeek(conValue,i);

        if (dimValue != "")
        {
            dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    return valueSetStorage.save();
}

So now I just changed upper post code into

ledgerAccount = DimensionDefaultingService::ServiceCreateLedgerDimension(_ledgerDimensionOrig, this.createDimensionDefault(dimValue));

Hope will help someone with same issue.

Have a great day!