web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Modify Dimension Set Entry table through code

(0) ShareShare
ReportReport
Posted on by 67

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;

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi,

    In which object you are trying to modify the code, go that object's property and set the Permission property of Dimension Set Entry table. and then try.

    Thanks.

  • Alzack18 Profile Picture
    67 on at

    Nitin Verma thank you for response.

    I created new CodeUnit file where I subscribe to event:

    codeunit 50101 "Before Post Validation"
    {
        [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";
            DimensionToChange: Record "Dimension Set Entry";
        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.", '3004');
    
            if SalesLines.FindSet() then
                repeat
                    Dimensions.SetRange("Dimension Set ID", SalesLines."Dimension Set ID");
                    Dimensions.SetRange("Dimension Code", 'MYCODE');
    
                    if Dimensions.FindSet() then
                        repeat
                            if (Dimensions."Dimension Value Code" = '123') 
                            or (Dimensions."Dimension Value Code" = '1234') then 
                            begin
                                DimensionToChange.SetRange("Dimension Set ID", SalesLines."Dimension Set ID");
                                DimensionToChange.SetRange("Dimension Code", 'TYPE');
                                DimensionToChange.Find('-');
                                DimensionToChange."Dimension Value Code" := 'SALES';
                                DimensionToChange.Modify; //this line causes an error, because no permission to modify
                            end;
                        until Dimensions.Next() = 0
                until SalesLines.Next() = 0
        end;
    }


    I want validate sales invoice before post. If special statement appears on line, I want to modify specific Dimension for this line.

    SalesLine have relation to "Dimension Set Entry" on  SalesLine."Dimension Set ID" = "Dimension Set Entry"."Dimension Set ID".

    I created new Permission Set to this table, but it didn't help. Of course I added this Permission Set to User Group, and User Group to user.

    pastedimage1662461530282v1.png

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi

    Can you please follow yellow mark? Check if it helps you.

    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";
    DimensionToChange: Record "Dimension Set Entry";
    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.", '3004');

    if SalesLines.FindSet() then
    repeat
    Dimensions.SetRange("Dimension Set ID", SalesLines."Dimension Set ID");
    Dimensions.SetRange("Dimension Code", 'MYCODE');

    if Dimensions.FindSet() then
    repeat
    if (Dimensions."Dimension Value Code" = '123')
    or (Dimensions."Dimension Value Code" = '1234') then
    begin
    DimensionToChange.SetRange("Dimension Set ID", SalesLines."Dimension Set ID");
    DimensionToChange.SetRange("Dimension Code", 'TYPE');
    DimensionToChange.Find('-');
    DimensionToChange."Dimension Value Code" := 'SALES';
    DimensionToChange.Modify; //this line causes an error, because no permission to modify
    end;
    until Dimensions.Next() = 0
    until SalesLines.Next() = 0
    end;
    }

  • Alzack18 Profile Picture
    67 on at

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

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi,

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

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

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

    pastedimage1662467261826v1.png

  • Alzack18 Profile Picture
    67 on at

    I'm using sandbox on docker instance.

  • Alzack18 Profile Picture
    67 on at

    Added "D365 BASIC" but still nothing :/

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    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
    67 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans