Showing posts with label Dimension. Show all posts
Showing posts with label Dimension. Show all posts

How to find or create default Dimension from X++ in AX 2012


How to find or create default Dimension from X++ in AX 2012


Following is the code you can use to find or create dimension in AX 2012


static DimensionDefault generateDefaultDimension(container _attr, container _value, boolean _createIfNotFound = true)
    {
        DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault result;
        int i;
        DimensionAttribute dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
        //_attr is dimension name in table DimensionAttribute
        container conAttr = _attr;
        container conValue = _value;
        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;
    }

Support Faryal's Cusine


Active Ledger Dimension


Active Ledger Dimension 


You can use the following code sample to tet ledger dimension values for active account structure in AX 2012 & D365FO


  public static DimensionValue getdimensionValue(LedgerDimensionAccount _ledgerDimension, Name _dimensionName )
    {
        DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensionsDimensionAttribute dimAttr; //Main dimension attribute table

        select DisplayValue from dimAttrViewwhere dimAttrView.ValueCombinationRecId == _ledgerDimension //generalJournalAccountEntry.LedgerDimensionjoin BackingEntityType from dimAttrwhere dimAttr.RecId == dimAttrView.DimensionAttribute&& dimAttr.Name == _dimensionName; // Dimension field name
        return dimAttrView.DisplayValue;
    }

Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...