Thursday, September 2, 2021

LCS Downloadable Tools

Ok..Ok..I've lost this page a number of times.  The downloadable tool page in LCS is:

https://lcs.dynamics.com/V2/LocalTools/

This page has all of the available tools for download, include IDMF, Data Import/Export and the Security Development tool.

Thursday, May 13, 2021

D365 for F&O: An Explanation of Ledger and Default Dimensions with Code

Another blogger finally illustrated the differences between Default Dimensions and Ledger Dimensions.  Quick Note: Default Dimensions are stored in DimensionAttributeValueSet and Ledger Dimensions are stored in DimensionAttributeValueCombinate.  Code to create a new dimension of each type is below.

Dimensions

For reference, the containers are an array of dimension attribute names/values in the order expected for the dimension:

container conAttr = ["MainAccount", "Division", "Department", "CostCentre", "Program"];

container conValue = [this.MainAccountId, this.BusinessUnit, this.Department, this.CostCenter, this.Program];

 //This method creates a default dimension in DimensionAttributeValueSet

    public static DimensionDefault createNewDefaultDimension(container _conAttr, container _conValue)

    {

        DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();

        DimensionDefault                    result;

        int                                 i;

        DimensionAttribute                  dimensionAttribute;

        DimensionAttributeValue             dimensionAttributeValue;


        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);

            }

        }

    

        result = valueSetStorage.save();


        return result;

    }


    //This method creates a ledger dimension found in DimensionAttributeValueCombination

    //Assumption: MainAccountId is expected in the container _conData

    public static LedgerRecId createNewLedgerDimension(MainAccountNum _mainAccountId, container _conValue)

    {

        int                                             hierarchyCount;

        int                                             hierarchyIdx;

        RecId                                           dimAttId_MainAccount;

        LedgerRecId                                     ledgerRecId;

        MainAccount                                     mainAccount;

        RefRecId                                        recordvalue;

        DimensionAttribute                              dimensionAttribute;

        DimensionAttributeValue                         dimensionAttributeValue;

        DimensionSetSegmentName                         dimensionSet;

        DimensionStorage                                dimStorage;

        LedgerAccountContract ledgerAccountContract =   new LedgerAccountContract();

        DimensionAttributeValueContract                 valueContract;

        List                                            valueContracts = new List(Types::Class);


        dimensionAttributeValueCombination dimensionAttributeValueCombination;


        mainAccount = MainAccount::findByMainAccountId(_mainAccountId);

        recordvalue = DimensionHierarchy::getAccountStructure(mainAccount.RecId,Ledger::current());

        hierarchyCount = DimensionHierarchy::getLevelCount(recordvalue);

        dimensionSet = DimensionHierarchyLevel::getDimensionHierarchyLevelNames(recordvalue);


        for(hierarchyIdx = 1; hierarchyIdx <= hierarchyCount; hierarchyIdx++)


        {

            if(hierarchyIdx == 1) //Main Account

                continue;


            dimensionAttribute = DimensionAttribute::findByLocalizedName(dimensionSet[hierarchyIdx],false,"en-us");


            if(dimensionAttribute)

            {

                dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, conPeek(_conValue,hierarchyIdx));


                if(dimensionAttributeValue)

                {

                    valueContract = new DimensionAttributeValueContract();

                    valueContract.parmName(dimensionAttribute.Name) ;

                    valueContract.parmValue(dimensionAttributeValue.CachedDisplayValue);

                    valueContracts.addEnd(ValueContract);

                }

            }

        }


        ledgerAccountContract.parmMainAccount(_mainAccountId);

        ledgerAccountContract.parmValues(valueContracts);

        dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);

        dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());

        ledgerRecId = dimensionAttributeValueCombination.RecId;


        return ledgerRecId;


    }