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;
Glad you got it working through the DimensionManagement codeunit!
Keep up the good work!
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; }
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.
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
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.
Added "D365 BASIC" but still nothing :/
I'm using sandbox on docker instance.
Can you please check if you have below permission with your user card?
Hi,
I tried the same code in my environment, and not getting any permission error, Are you using OnPrem or Cloud?
I added this yellow line, but it didn't help.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,888 Super User 2024 Season 2
Martin Dráb 229,247 Most Valuable Professional
nmaenpaa 101,156