Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

multiple external codes to sale invoice

Posted on by 6
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:
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 63,357 Super User on at
    multiple external codes to sale invoice
    Got it, the easiest way is not to use a variable, add an actual field to the table. Variables are only calculated when the page is opened. Therefore, variables cannot be directly added to the report as a Column of DataItem.
    If you don't want to do this, you can get the value through the page function, but you need to rewrite the logic. This is a little more complicated than you might think since you can't use "Rec".
    For example,
     
    Sorry I haven't tested it, but I think you don't have to use the page, it might be faster to rewrite the logic in the report.
     
    Hope this can give you some hints.
    Thanks.
    ZHU
  • CU02071827-0 Profile Picture
    CU02071827-0 6 on at
    multiple external codes to sale invoice
    Yes, code is empty, but if posting from sale order i am geting external codes not from sale orders but from posted sale orders… problem not with code, problem with how to get that value from page to report. (standart sales invoice)… because i know how to get valyes only from table, not from page…
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 63,357 Super User on at
    multiple external codes to sale invoice
    Hi, I took a quick look at your code and found a problem.
    If your invoice is posted from an order, "Shipment No." will always be empty. Then according to your code, you will get the value of salesOrderHeader at this time, but the Sales Order no longer exists (it is automatically deleted), so you cannot get the value.
     
    Hope the this helps.
    Thanks.
    ZHU
  • gdrenteria Profile Picture
    gdrenteria 4,516 Super User on at
    multiple external codes to sale invoice
    Hi
    What's the problem? You always get a blank? Do you get wrong information?
    BR
    GR

Helpful resources

Quick Links

First Dynamics 365 Community Call (CRM Edition)

Don't miss the first D365 Community Call on 7/10!

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 285,480 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,450 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans