Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Modify Dimension Set Entry table through code

Posted on by 65

Hi

I want to edit dimensions for my salesLine. I found that each line has relation to Dimension Set Entry. I wrote code to modify that record, but I don't have permission to modify Dimension Set Entry table. I already added all admin permission to my user, but it doesn't helps.

What should I do?


My code:

DimensionToChange.SetRange("Dimension Set ID", SalesLines."Dimension Set ID");
DimensionToChange.SetRange("Dimension Code", 'TYPE');
DimensionToChange.Find('-');
DimensionToChange."Dimension Value Code" := 'SALES';
DimensionToChange.Modify;

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Modify Dimension Set Entry table through code

    Glad you got it working through the DimensionManagement codeunit!

    Keep up the good work!

  • Alzack18 Profile Picture
    Alzack18 65 on at
    RE: Modify Dimension Set Entry table through code

    Thank you for helpful tips. Problem solved using CodeUnit "DimensionManagement"!

    I had problem, that after adding new Dimension and changing SalesLines."Dimension Set ID" I was losing rest dimensions on that line.

    Solution was to use: DimManagement.GetDimensionSet(TempDimSetEntry, SalesLines."Dimension Set ID");

    to store all dimensions.

    This topic was helpful: community.dynamics.com/.../801556

    My actual code:

    codeunit 50101 "Before Post Validation"
    {
        Permissions = tabledata "Dimension Set Entry" = RM;
        [EventSubscriber(ObjectType::CodeUnit, Codeunit::"Sales-Post (Yes/No)", 'OnBeforeConfirmSalesPost', '', false, false)]
        local procedure OnBeforeConfirmSalesPost(var SalesHeader: Record "Sales Header"; var HideDialog: Boolean; var IsHandled: Boolean; var DefaultOption: Integer; var PostAndSend: Boolean)
        var
            SalesLines: Record "Sales Line";
            Dimensions: Record "Dimension Set Entry";
            TempDimSetEntry: Record "Dimension Set Entry" temporary;
            DimManagement: Codeunit DimensionManagement;
        begin
            SalesLines.SetRange("Document No.", SalesHeader."No.");
            SalesLines.SetRange("Document Type", SalesHeader."Document Type");
            SalesLines.SetRange(Type, "Sales Line Type"::"G/L Account");
            SalesLines.SetRange("No.", '1234');
    
            if SalesLines.FindSet() then begin
                repeat
                    Dimensions.SetRange("Dimension Set ID", SalesLines."Dimension Set ID");
                    Dimensions.SetRange("Dimension Code", 'SPECIFICCODE');
    
                    if Dimensions.Find('-') then
                        if (Dimensions."Dimension Value Code" = '123')
                        or (Dimensions."Dimension Value Code" = '1234') then
                        begin
                            DimManagement.GetDimensionSet(TempDimSetEntry, SalesLines."Dimension Set ID");
    
                            TempDimSetEntry.Init();
                            TempDimSetEntry.Validate("Dimension Code", 'MYCODE');
                            TempDimSetEntry.Validate("Dimension Value Code", 'MYVALUE');
                            
                            if not TempDimSetEntry.Insert then
                                TempDimSetEntry.Modify;
    
                            SalesLines.Validate("Dimension Set ID", DimManagement.GetDimensionSetID(TempDimSetEntry));
                            SalesLines.Modify;
                        end;
                until SalesLines.Next() = 0;
            end;
        end;
    }

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Modify Dimension Set Entry table through code

    If i understand you correctly then what you want to do is under certain conditions to change the dimension for one or more lines on your sales Lines.

    To do that you should change the Dim set ID on the sales line. And to get the correct value for the dim set id you should use the function in the DimensionManagement codeunit called GetDimensionSetID

    That takes a temporary Dimension Set Entry table as parameter and returns the corresponding Dimension Set ID.

    Once a dimension set is created you should never change the dimensions or dimension values combinations  that the dimension set  is build from.

    A tip is to set the Dimension set ID to -1 one the temporary records you pass into the GetDimensionSetID function.

    I have a code sample somewhere. I will post it here as soon as i find it.

  • Alzack18 Profile Picture
    Alzack18 65 on at
    RE: Modify Dimension Set Entry table through code

    Inge M. Bruvik thank you for response.

    Can you please indicate which function I should use to achieve the same as with my code?

    That is, edit the record that has the "Dimension Code" equal to the indicated value and set the "Dimension Value Code" on it.

    Best regards

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Modify Dimension Set Entry table through code

    You should avoid coding directly in that table. All changes to the dimension sets should be done using the DimensionManagement codeunit. If not you run a risk of compromising the integrity of your transactions and your dimension data.

    This Dim. management codeunit should have every function you need to work with dimensions sets in a safe way.

  • Alzack18 Profile Picture
    Alzack18 65 on at
    RE: Modify Dimension Set Entry table through code

    Added "D365 BASIC" but still nothing :/

  • Alzack18 Profile Picture
    Alzack18 65 on at
    RE: Modify Dimension Set Entry table through code

    I'm using sandbox on docker instance.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Modify Dimension Set Entry table through code

    Can you please check if you have below permission with your user card?

    pastedimage1662467261826v1.png

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Modify Dimension Set Entry table through code

    Hi,

    I tried the same code in my environment, and not getting any permission error, Are you using OnPrem or Cloud?

  • Alzack18 Profile Picture
    Alzack18 65 on at
    RE: Modify Dimension Set Entry table through code

    I added this yellow line, but it didn't help.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans