Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum
Under review by Community Managers

Under review

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

multiple external codes to sale invoice

Posted on by
Hello,
 
I am newbie, but still..Trying to get multiple exteral codes to Standard Sales - Invoice. And unsuccessful :( 
 
i wrote a code, which is on page, not table.. So maybe someone could help me and give me a guide or lesson, how to transfer page field to Standard Sales - Invoice or maybe some can say how to quick transform from page to table field ( because from table i think i know how to get field) ? 
 
And code is : 
 
 
pageextension 50129 saleorderlistas extends "Posted Sales Invoice"
{
    layout
    {
        addafter("No.")
        {
            field(socodesField; socodes)
            {
                ApplicationArea = All;
                Caption = 'SO Codes';
                ToolTip = 'SO Codes';
                Editable = false;
            }
        }
    }
    trigger OnAfterGetCurrRecord()
    var
        saleInvoiceLine: Record "Sales Invoice Line";
        salesShipmentLine: Record "Sales Shipment Line";
        salesOrderHeader: Record "Sales Header";
        asalesOrderHeader: Record "Sales Header Archive";
        shippingNo: Code[20];
        itemNo: Code[20];
        orderNo: Code[20];
    begin
        socodes := ''; 
        saleInvoiceLine.Reset();
        saleInvoiceLine.SetRange("Document No.", Rec."No.");
        saleInvoiceLine.SetRange(Type, saleInvoiceLine.Type::Item);
        if saleInvoiceLine.FindSet() then begin
            repeat
                shippingNo := saleInvoiceLine."Shipment No.";
                itemNo := saleInvoiceLine."No.";
                orderNo := saleInvoiceLine."Order No.";
                if shippingNo = '' then begin
                    asalesOrderHeader.Reset();
                    asalesOrderHeader.SetRange("No.", orderNo);
                    if asalesOrderHeader.FindFirst() then begin
                        if socodes <> '' then
                            socodes += ', ' + asalesOrderHeader."No."
                        else
                            socodes := asalesOrderHeader."No.";
                    end;
                end else begin
                    salesShipmentLine.Reset();
                    salesShipmentLine.SetRange("Document No.", shippingNo);
                    salesShipmentLine.SetRange("No.", itemNo);
                    if salesShipmentLine.FindSet() then begin
                        repeat
                            salesOrderHeader.Reset();
                            salesOrderHeader.SetRange("No.", salesShipmentLine."Order No.");
                            if salesOrderHeader.FindFirst() then begin
                                if socodes <> '' then
                                    socodes += ', ' + salesOrderHeader."No."
                                else
                                    socodes := salesOrderHeader."No.";
                            end;
                        until salesShipmentLine.Next() = 0;
                    end;
                end;
            until saleInvoiceLine.Next() = 0;
        end;
    end;
    var
        socodes: Text;
}
 
Categories:

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans