Create and Assign Dimensions in Sales Document at Creation in BC D365

Create and Assign Dimensions in Sales Document:

(1) In this blog, we will do auto-creation and assignment of Dimensions in Sales Document creation (or OnInsert Trigger) as shown below.

auto-creation and assignment of Dimensions in Sales Document creation in bc d365

(2) In the above function, we have called EventSubscriber of Sales Header table OnAfterInsertEvent for auto assigning the value to Sales Document.

Source Code:

codeunit 50001 “Custom Functions-01”
{
    [EventSubscriber(ObjectType::Table, Database::”Sales Header”, ‘OnAfterInsertEvent’, ”, true, true)]
    procedure OnAfterInsertValueInSO(Rec: Record “Sales Header”; Runtrigger: Boolean)
    var
DimensionValue: Record “Dimension Value”;
GeneralLedgerSetup: Record “General Ledger Setup”;
InsertDimensionValue: Record “Dimension Value”;
    begin
GeneralLedgerSetup.get;
GeneralLedgerSetup.testfield(“Global Dimension 1 Code”);
DimensionValue.reset;
DimensionValue.setrange(“Dimension Code”, GeneralLedgerSetup.”Global Dimension 1 Code”);
DimensionValue.setrange(Code, Rec.”No.”);
        if not DimensionValue.FindFirst() then begin
InsertDimensionValue.init;
InsertDimensionValue.validate(“Dimension Code”, GeneralLedgerSetup.”Global Dimension 1 Code”);
InsertDimensionValue.validate(“Code”, Rec.”No.”);
InsertDimensionValue.validate(“Global Dimension No.”, 1);
InsertDimensionValue.Validate(Name, Rec.”No.”);
InsertDimensionValue.insert;
        end;
    end;

Convert Amount into Words in D365 BC
MODIFY and MODIFYALL in D365 BC
FlowField in Dynamics 365 BC
How to Import EXCEL data in Business Central D365
Working with Dimensions– Microsoft Docs

Leave a Reply