Search code examples
microsoft-dynamicsnavisiondynamics-business-central

Assign a value from Gen Business Posting Group Table


I have got Gen Bus. Posting Group field showing on the subform of Sales Order. This Subform is also showing Location Code for the Line.

I am attempting to write a logic as such that if the User selects Location Code as DROPSHIP, the Gen Bus. Posting Group should be LOCAL-DROPSHIP.

LOCAL-DROPSHIP is a record in the Gen. Bus. Posting Group. I have created it before writing this code. However, it would not assign to my rec.Gen Bus. Posting Group.

Here is the code on the Subform;

modify("Location Code")
    {
        trigger OnAfterValidate()
        var
            recLocation: Record Location;
            recCustomer: Record Customer;
            recSalesLine: Record "Sales Line";
            recGenPosting: Record "Gen. Business Posting Group";

        begin
            recGenPosting.Get('LOCAL-DS');
            if rec."Location Code" = 'DROPSHIP' then begin
                Message(recGenPosting.Code);
               // Validate("Gen. Bus. Posting Group", recGenPosting.Code);
                Rec."Gen. Bus. Posting Group" := recGenPosting.Code;
                CurrPage.Update();
            end;
        end;
    }

Solution

  • Extended Sales Line table, on the OnModify trigger, wrote;

       if rec."Location Code" = 'DROPSHIP' then begin
                If recCustomer.Get(REC."Sell-to Customer No.") THEN begin
                    if recCustomer."Country/Region Code" = 'CITY' then begin
                        rec."Gen. Bus. Posting Group" := 'DS';
                        rec.Modify();
                    end
            end