Set Financial Dimension combination for Purchase line using X++

In this article we will see how to set financial dimension combination for a PurchLine using X++ code.

Please follow the code below to set the financial dimensions.

        PurchLine                           purchLine;
        DimensionAttributeValueSetStorage   dimensionAttributeValueSetStorage;
        DimensionAttributeValue             dimensionAttributeValue;
        DimensionAttribute                  dimensionAttribute;
        container                           financialDimensionName;
        container                           financialDimensionValue;
        int                                 i;

        financialDimensionName  = ['BusinessUnit', 'CostCenter', 'Department', 'ItemGroup', 'Project'];
        financialDimensionValue = ['001', '007', '022', 'AudioRM', '000002'];

        purchLine  =  PurchLine::find('000038', 1);

        dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();

        for (i = 1; i <= conLen(financialDimensionName); i++)
        {
            dimensionAttribute      = DimensionAttribute::findByName(conPeek(financialDimensionName, i));
            dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, conPeek(financialDimensionValue, i), false, true);
            
            if (dimensionAttributeValue)
            {
                dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue);
            }
        }

        ttsBegin;
        purchLine.selectForUpdate(true);
        purchLine.DefaultDimension = dimensionAttributeValueSetStorage.save();
        purchLine.update();
        ttsCommit;

You can use the same code for others like Sales line etc. just replace the PurchLine buffer with the SalesLine etc.

Thank you for reading this article hope you find it useful.

Omar Iqbal

Technical Consultant

Total
0
Shares
8 comments
  1. Howdy! I just wish to give you a huge thumbs up foryour great info you have got here on this post.I will be returning to your blog for more soon.

  2. All those guidelines In addition worked to be a good way to recognize that other people on the internet hold the similar fervor like mine to grasp great deal a lot more all around this condition.

  3. Hello! I could have sworn Iíve been to this blog before but after going through some of the posts I realized itís new to me. Anyways, Iím definitely happy I found it and Iíll be book-marking it and checking back often!

Comments are closed.

Previous Article

Posting a Product Receipt with Item Registration through X++ code

Next Article

Inventory consignment ownership process in Microsoft Dynamics Finance & Operations

Related Posts