Blog Listem

24 Haziran 2014 Salı

AX 2012 - Default dimension

//http://axvuongbao.blogspot.com.tr/2013/08/how-to-create-default-dimension-from-x.html
public static DimensionDefault CreateDefaultDim(Container _a,Container _v)
{

    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                               result;
    int                                                      i;
    DimensionAttribute                            dimensionAttribute;
    DimensionAttributeValue                   dimensionAttributeValue;
    //_attr is dimension name in table DimensionAttribute
    container               conAttr  =  _a;
    container               conValue =   _v;
    boolean                 _createIfNotFound = true;
    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 != "")
        {
            // _createIfNotFound is "true". A dimensionAttributeValue record will be created if not found.
            dimensionAttributeValue=
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,_createIfNotFound);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }
    result = valueSetStorage.save();

    return result;
}


Kullanımı:

LedgerJournalTrans.DefaultDimension = MyUtility::CreateDefaultDim("[Contract],[Project]","[0001],[MyBigProject]")

Eğer Unable to return DimensionAttributeValue record for ... gibi bir hata alırsanız sistemde kayıtlı olmayan bir dimension value değerine kombinasyon oluşturmaya çalışıyorsunuz demektir.

Hiç yorum yok:

Yorum Gönder