Inkey Solution Logo
banner

Blogs

Dynamics 365 Business Central: Retrieve Linked Sales Order Data in Assembly Orders Using AL Code

, June 27, 2024 338 Views

Dynamics 365 Business Central is a powerful Enterprise Resource Planning (ERP) solution that offers a wide range of customization options to meet the unique needs of your business. One such customization is to get linked Sales order’s data in Assembly Order. This customization can be used for businesses that deal with complex assembly processes and require visibility into the sales orders associated with assembly orders.

Requirement:

We recently encountered a requirement where we need to retrieve linked sales order data in assembly order. The objective was to enable users to effortlessly access relevant sales order information directly from the assembly order.

Prerequisites:

  • Access to a Microsoft Dynamics 365 Business Central instance with administrator privileges.
  • Visual Studio Code with AL Language extension installed.

Solution (Implementation Steps):

In Microsoft Dynamics Business Central, to Retrieve Linked Sales Order Data in Assembly Orders, follow these implementation steps:

Step 1: Create a TableExtension and Add Fields:

Create a table extension for the Assembly Order table and add fields to it to store the linked sales order data as shown in code below.

tableextension 90102 VAS_Assembly_Order extends "Assembly Header"
{
    fields
    {
        field(90100; "Sales Order No"; Code[20])
        {
            DataClassification = ToBeClassified;
        }
        field(90101; "Customer No"; Code[20])
        {
            DataClassification = ToBeClassified;
        }
        field(90102; "Customer Name"; Text[2048])
        {
            DataClassification = ToBeClassified;
        }
    }
}

Step 2: Create a PageExtension and Add Fields:

After adding fields to the table extension, you need to create a page extension to display these fields on the Assembly Order page.

pageextension 90111 VAS_Assembly_Order extends "Assembly Order"
{
    layout
    {
        addafter(Status)
        {
            field("Sales Order No"; Rec."Sales Order No")
            {
                ApplicationArea = All;
                Editable = false;

                trigger OnDrillDown()
                var
                    myInt: Integer;
                begin
                    Rec.ShowAsmToOrder();
                end;
            }
            field("Customer No"; Rec."Customer No")
            {
                ApplicationArea = All;
                Editable = false;
            }
            field("Customer Name"; Rec."Customer Name")
            {
                ApplicationArea = All;
                Editable = false;
            }
        }
    }
}

Step 3: Populate Data into these fields from the linked Sales Order:

 Use the OnAfterGetRecord trigger to fetch data from the Sales Order linked to the Assembly Order and populate the fields accordingly. This trigger is executed after a record is retrieved from the database.

Declaration of Variables:

  • Two record variables are declared: ATOLink and SalesHeader. These variables represent records named “Assemble-to-Order Link” and “Sales Header” respectively.

Condition Check:

  • The trigger begins with a condition check: if the current record has the “Assemble to Order” field set to true, the trigger proceeds; otherwise, it terminates.

Assemble-to-Order Link Retrieval:

  • Reset(): Resets the record buffer to prepare for a new query.
  • SetRange(): Sets filters on fields “Assembly Document Type” and “Assembly Document No.” to match the current document type and number.
  • FindSet(): Searches for records matching the specified criteria. If found, it proceeds to retrieve data.

Sales Order No. Assignment:

  • If a matching record is found in the “Assemble-to-Order Link” table, the “Sales Order No.” field of the current record is updated with the corresponding value from ATOLink.”Document No.”.

Customer Information Retrieval:

  • Reset(): Resets the Sales Header record buffer.
  • SetRange(): Sets filters on fields “Document Type” and “No.” to match the current document type and the “Document No.” obtained from the Assemble-to-Order Link.
  • FindSet(): Searches for records in the Sales Header table based on the provided filters.
  • If a matching record is found, the “Customer No.” and “Customer Name” fields of the current record are updated with the corresponding values from the Sales Header.

Record Modification:

  • Rec.Modify(true): Commits the changes made to the current record to the database.
pageextension 90111 VAS_Assembly_Order extends "Assembly Order"
{
    layout
    {
        addafter(Status)
        {
            field("Sales Order No"; Rec."Sales Order No")
            {
                ApplicationArea = All;
                Editable = false;

                trigger OnDrillDown()
                var
                    myInt: Integer;
                begin
                    Rec.ShowAsmToOrder();
                end;
            }
            field("Customer No"; Rec."Customer No")
            {
                ApplicationArea = All;
                Editable = false;
            }
            field("Customer Name"; Rec."Customer Name")
            {
                ApplicationArea = All;
                Editable = false;
            }
        }
}

    trigger OnAfterGetRecord()
    var
        ATOLink: Record "Assemble-to-Order Link";
        SalesHeader: Record "Sales Header";
    begin
        if Rec."Assemble to Order" = true then begin
            ATOLink.Reset();
            ATOLink.SetRange("Assembly Document Type", Rec."Document Type");
            ATOLink.SetRange("Assembly Document No.", Rec."No.");
            if ATOLink.FindSet() then begin
                Rec."Sales Order No" := ATOLink."Document No.";
                SalesHeader.Reset();
                SalesHeader.SetRange("Document Type", Rec."Document Type");
                SalesHeader.SetRange("No.", ATOLink."Document No.");
                if SalesHeader.FindSet() then begin
                    Rec."Customer No" := SalesHeader."Sell-to Customer No.";
                    Rec."Customer Name" := SalesHeader."Sell-to Customer Name";
                end;
                Rec.Modify(true);
            end;
        end;
    end;
}

Step 4: Publish and Install the Extension

After creating the custom report, you’ll need to publish and install the extension in your Dynamics 365 Business Central instance.

Step 5: Test the Customization

Test the customization thoroughly to ensure it works as expected and meets your business requirements

Conclusion:

In conclusion, this is one of the Dynamics 365 Business Central Solutions demonstrates a streamlined approach to retrieving linked sales order data within assembly orders in Business Central. By leveraging AL code and customization capabilities, businesses can efficiently integrate sales order information into their assembly processes, enhancing visibility and facilitating informed decision-making. This customization empowers users to navigate complex assembly workflows with ease, ultimately optimizing operational efficiency and driving business success.

This is just among the many solutions that Inkey IT Solutions Pvt. Ltd. can provide for all your Business Central related needs.

mm

Inkey

INKEY is your solution partner.
Our focus is to deliver you in-time intelligent innovative solutions ("key") for the problems in hand. Maintaining a quality standard right from the inception of a project is our top most priority.

Our team of talented professionals will execute your projects with dedication and excellence. We take ownership and accountability for the effort that goes into meeting our client’s needs.

Years of experience and proven success of delivering innovative custom solutions.

More posts by

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 2 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Drop file here

Would you like to digitize your business and put it on the cloud?
Do you need clear, concise reports for your organization?