web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Show data from custom field on another page

(0) ShareShare
ReportReport
Posted on by 25

Hello, I've read what I can on this and am at a roadblock I cannot pass.  I have extended the Sales Line table and Sales Order Subform page to include a new Line_No (text[10) to allow our users to enter a customer defined line number from their purchase order (i.e. 00010, 200, etc etc).  I have this transferring without issue to Sales Invoices and Posted Sales Invoices using a TableRelation in the tableextension, however the same methods do not seem to work to transfer to the Warehouse Shipment Line.  Full disclosure, I am not a BC developer, however am familiar with AL on a basic level.

How can I transfer this to our Warehouse Shipment after using Get Source Document?  I really only need this to transfer from the sales order lines, not transfer orders, or return orders.

The closest I feel I've been able to get to this is with this code, however no luck.

pageextension 50113 lineno_50113 extends "Whse. Shipment Subform"
{
    layout
    {
        addafter("Source No.")
        {
            Field("Line_No"; Rec.Line_No)
            {
                ApplicationArea = All;
            }
        }
    }
    trigger OnAfterGetRecord();
    var
        SalesLine: Record "Sales Line";
    begin
        SalesLine.Reset();
        SalesLine.Get(Rec."No.", Rec.Line_No);
        Rec.Line_No := SalesLine.Line_No;
    end;

Below are my table extensions:

tableextension 50110 lineno_50110 extends "Sales Line"
{
    fields
    {
        field(50110; Line_No; text[10])
        {
            DataClassification = ToBeClassified;
            Caption = 'Line No.';
        }
    }
}

tableextension 50111 lineno_50111 extends "Sales Invoice Line"
{
    fields
    {
        field(50110; Line_No; text[10])
        {
            DataClassification = ToBeClassified;
            Caption = 'Line No.';
            TableRelation = "Sales Line"."Line_No" WHERE("Document No." = FIELD("Document No."));
        }
    }
}

tableextension 50112 lineno_50112 extends "Warehouse Shipment Line"
{
    fields
    {
        field(50110; Line_No; text[10])
        {
            DataClassification = ToBeClassified;
            Caption = 'Line No.';
            //TableRelation = "Sales Line"."Line_No" WHERE("Document No." = FIELD("Source No."));
        }
    }
}

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

    I would have a look for a table or codeunit event so you can populate the field directly that way. Sales works as they are similar tables so transferfields does the job. Warehouse covers a number of documents so tables aren’t as similar. This will help you find a relevant event: 

    https://docs.microsoft.com/en-us/dynamics365-release-plan/2020wave1/dynamics365-business-central/lookup-events-insert-event-subscriber-code

  • mikef_syl Profile Picture
    25 on at

    Hi Josh, it looks like I got it working by adding a single EventSubscriber to OnBeforeCreateShptLineFromSalesLine, but would like a second set of eyes to look at this.

        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Create Source Document", 'OnBeforeCreateShptLineFromSalesLine', '', false, false)]
        local procedure GetSalesDocInfo(var WarehouseShipmentLine: Record "Warehouse Shipment Line"; WarehouseShipmentHeader: Record "Warehouse Shipment Header"; SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header");
        begin
            SalesHeader.Get(SalesLine."Document Type", SalesLine."Document No.");
            with WarehouseShipmentLine do begin
                SetSource(DATABASE::"Sales Line", SalesLine."Document Type".AsInteger(), SalesLine."Document No.", SalesLine."Line No.");
                if SalesLine.Line_No <> '' then
                    Line_No := SalesLine."Line_No"
                else
                    Line_No := '';
            end;
        end;

  • Suggested answer
    JAngle Profile Picture
    133 on at

    the parameters of GetSalesDocInfo are already in context so the .GET and with do begin are not required. It will run this for every warehouse shipment line so 1 by 1. Also the with statement is being deprecated so try to avoid using it.

    If the new field "Line_No" exists in both tables you basically just need lines 7 to 10 rest can be deleted.

  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    You just need to add one line, you don't need all the Get Statement or other code

    WarehouseShipmentLine."New Field Name." := SalesLine."New Field Name";

  • mikef_syl Profile Picture
    25 on at

    Josh, Suresh, thank you so much, your answers have both helped me find the method to use to do this and has greatly simplified my code.  My next issue is getting this new field into the Posted Sales Shipment table.  I've found two events which I believe will work - OnBeforePostUpdateWhseDocuments & OnBeforeDeleteUpdateWhseShptLine.

    It looks like I may need to insert this new field in a buffer table first?  OnBeforeDeleteUpdateWhseShptLine uses the correct objects and I can get the new field.  I am unsure how to get this new data to carry over through the posting.

    Any further assistance would be greatly appreciated.

  • Suggested answer
    mikef_syl Profile Picture
    25 on at

    For anyone that runs across this post, in order to get the custom field from the sales lines to transfer, I had to transfer both to Posted Warehouse Shipments and Posted Sales Shipments.  A copy document gets called after the warehouse shipment is posted, which copies to Posted Sales Shipments.  I'm not sure if I need to subscribe to all the events that I am below, but it is working and I'm leaving it as-is for now:

        // Below carries custom Line_No field over from the Sales Order to Warehouse Shipment Lines
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Create Source Document", 'OnBeforeCreateShptLineFromSalesLine', '', false, false)]
        // Procedure can only take objects defined by the event
        local procedure GetSalesDocLineNo(var WarehouseShipmentLine: Record "Warehouse Shipment Line"; WarehouseShipmentHeader: Record "Warehouse Shipment Header"; SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header");
        var
        begin
            WarehouseShipmentLine."Line_No" := SalesLine."Line_No";
        end;
    
        // Below carries custom Line_No field over from the Warehouse Shipment to Posted Warehouse Shipment
        [EventSubscriber(ObjectType::CodeUnit, CodeUnit::"Whse.-Post Shipment", 'OnCreatePostedShptLineOnBeforePostedWhseShptLineInsert', '', false, false)]
        local procedure PostWhseShipLineNo(var PostedWhseShptLine: Record "Posted Whse. Shipment Line"; WhseShptLine: Record "Warehouse Shipment Line");
        begin
            PostedWhseShptLine.Line_No := WhseShptLine."Line_No";
        end;
    
        // Same
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Post Shipment", 'OnAfterInitPostedShptLine', '', false, false)]
        local procedure GetShipmentLineNo(var WhseShipmentLine: Record "Warehouse Shipment Line"; var PostedWhseShipmentLine: Record "Posted Whse. Shipment Line")
        begin
            PostedWhseShipmentLine."Line_No" := WhseShipmentLine."Line_No";
        end;
    
        // Same
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Post Shipment", 'OnBeforePostWhseJnlLine', '', false, false)]
        local procedure OnBeforePostWhseJnlLine(var PostedWhseShipmentLine: Record "Posted Whse. Shipment Line"; var TempTrackingSpecification: Record "Tracking Specification" temporary; var IsHandled: Boolean)
        begin
            PostedWhseShipmentLine."Line_No" := PostedWhseShipmentLine."Line_No";
        end;
    
        // Same
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Post Shipment", 'OnBeforeRegisterWhseJnlLines', '', false, false)]
        local procedure OnBeforeRegisterWhseJnlLines(var TempWhseJnlLine: Record "Warehouse Journal Line"; var PostedWhseShptLine: Record "Posted Whse. Shipment Line")
        begin
            TempWhseJnlLine."Line_No" := PostedWhseShptLine."Line_No";
        end;
    
        // Below carries custom Line_no field over to the Posted Sales Shipment
        [EventSubscriber(ObjectType::Table, 111, 'OnAfterInitFromSalesLine', '', false, false)]
        local procedure OnAfterInitFromSalesLine(SalesShptHeader: Record "Sales Shipment Header"; SalesLine: Record "Sales Line"; var SalesShptLine: Record "Sales Shipment Line")
        begin
            SalesShptLine."Line_No" := SalesLine."Line_No";
        end;
    

Under review

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

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans