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

Sales Order Bill-to Address Code Customization

(8) ShareShare
ReportReport
Posted on by 683
Sales Orders have the option of using the Ship-to "Alternate Shipping Address" where a Ship-to Code can be entered to populate address information from the list of Customer Shipping Addresses.  I am working on a GP to BC migration where the GP Addresses consist of both Shipping & Billings address codes, and we are migrating all Customer Address codes to the BC Shipping Codes.
 
We would like for the BC Sales Orders to have the same option for Billing Addresses as Shipping (select Alternate Billing Address, the supply a code from the Shipping Address table to fill in the Billing Address information).
 
Has anyone done anything like that?  I know there is an add-on out there that does something similar, but I would really just like to create the AL code to do it.  I get close, but cannot seem to get it worked out 100%.
 
Any thoughts or code examples would be great, thanks.
I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at
    As you explained the logic is simple, you just need another field to select the code from your custom table where you would like to store the addresses and then on validation update the bill-to address fields.  Send your issue or AL code which is not working.
  • Suggested answer
    Jainam M. Kothari Profile Picture
    15,639 Super User 2025 Season 2 on at
    Hello,
     
    Earlier there is a Functionality called "Order Address" is available in the BC. But now it is Not Available.
     
    So, you need to Customize the "Bill to Codes" same as Ship to Code Functionality. 
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,603 Super User 2025 Season 2 on at
    Yes, you can customize Sales Orders in Business Central to allow selecting an Alternate Bill-to Address using the existing Customer Shipping Addresses.
    You just need to add another field (like "Alternate Bill-to Address Code") to select the code from a custom table (where you store addresses — could be "Ship-to Address" or your own custom table).  Then, on the OnValidate trigger of that field, update the Bill-to address fields (Bill-to Name, Bill-to Address, City, etc.).
     
  • ME-31032107-0 Profile Picture
    683 on at
    Below is the code I have written so far.  What is currently happening is that when I change the Bill-to Option to "Alternate Billing Address", I am able to select a Bill-to Code from the list (which is the Ship-to Address List), but then the Bill-to Option flips back to "Default (Customer)" and I cannot see the Bill Address Control group control (like when "Custom Address" is selected).
     
    I'm sure it is something simple I am missing.  Once I get past this, then I am hopeful that the Bill-to Code Name & Address information will get populated based on the selected Bill-to Code.
     
    Thanks.
     
    pageextension 50101 SalesCardExtension extends "Sales Order"
    {
        layout
        {
            modify(BillToOptions)
            {
                trigger OnAfterValidate()
                var
                    BillToAddress: Record "Ship-to Address";
                    BillToAddressList: Page "Ship-to Address List";
                    IsHandled: Boolean;
                begin
                    IsHandled := false;
                    OnBeforeValidateBillToOptions(Rec, BillToOptions.AsInteger(), IsHandled);
                    if IsHandled then
                        exit;
                    case BillToOptions of
                        BillToOptions::"Default (Customer)":
                            begin
                                Rec.Validate("Bill-to Code", '');
                            end;
                        BillToOptions::"Another Customer":
                            begin
                                Rec.Validate("Bill-to Code", '');
                            end;
                        BillToOptions::"Custom Address":
                            begin
                                Rec.Validate("Bill-to Code", '');
                            end;
                        BillToOptions::"Alternate Billing Address":
                            begin
                                BillToAddress.SetRange("Customer No.", Rec."Sell-to Customer No.");
                                BillToAddressList.LookupMode := true;
                                BillToAddressList.SetTableView(BillToAddress);
                                if BillToAddressList.RunModal() = ACTION::LookupOK then begin
                                    BillToAddressList.GetRecord(BillToAddress);
                                    OnValidateBillToOptionsOnAfterBillToAddressListGetRecord(BillToAddress, Rec);
                                    Rec.Validate("Bill-to Code", BillToAddress.Code);
                                    IsBillToCountyVisible := FormatAddress.UseCounty(BillToAddress."Country/Region Code");
                                end else
                                    BillToOptions := BillToOptions::"Custom Address";
                            end;
                    end;
                    OnAfterValidateBillingOptions(Rec, BillToOptions.AsInteger());
                end;
            }
            addafter(BillToOptions)
            {
                field("Bill-to Code"; Rec."Bill-to Code")
                {
                    ApplicationArea = Basic, Suite;
                    Caption = 'Code';
                    Visible = BillToOptions = BillToOptions::"Alternate Billing Address";
                    Editable = BillToOptions = BillToOptions::"Alternate Billing Address";
                    Importance = Promoted;
                    ToolTip = 'Specifies the code for another billing address than the customer''s own address, which is entered by default.';
                    trigger OnValidate()
                    var
                        BillToAddress: Record "Ship-to Address";
                    begin
                        if (xRec."Bill-to Code" <> '') and (Rec."Bill-to Code" = '') then
                            Error(EmptyBillToCodeErr);
                        if Rec."Bill-to Code" <> '' then begin
                            BillToAddress.Get(Rec."Sell-to Customer No.", Rec."Bill-to Code");
                            IsBillToCountyVisible := FormatAddress.UseCounty(BillToAddress."Country/Region Code");
                        end else
                            IsBillToCountyVisible := false;
                    end;
                }
            }
        }
        var
            EmptyBillToCodeErr: Label 'The Code field can only be empty if you select Custom Address in the Bill-to field.';
            IsBillToCountyVisible: Boolean;
            FormatAddress: Codeunit "Format Address";
        [IntegrationEvent(false, false)]
        local procedure OnBeforeValidateBillToOptions(var SalesHeader: Record "Sales Header"; BillToOptions: Option "Default (Customer)","Another Customer","Custom Address","Alternate Billing Address"; var IsHandled: Boolean)
        begin
        end;
        [IntegrationEvent(false, false)]
        local procedure OnValidateBillToOptionsOnAfterBillToAddressListGetRecord(var BillToAddress: Record "Ship-to Address"; var SalesHeader: Record "Sales Header")
        begin
        end;
        [IntegrationEvent(false, false)]
        local procedure OnAfterValidateBillingOptions(var SalesHeader: Record "Sales Header"; BillToOptions: Option "Default (Customer)","Another Customer","Custom Address","Alternate Billing Address")
        begin
        end;
    }
  • Verified answer
    ME-31032107-0 Profile Picture
    683 on at
    I was able to modify and enhance my code, and now the customization works perfectly. I had to extend the code on the Sales Orders Page, Sales Header Table and the Enum value for the BillToOptions dropdown.
     
    If anyone is interested in the code, let me know.
  • DK-22102111-0 Profile Picture
    6 on at
    Yes, please post the updated code...
  • Suggested answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at
    Hi, hope the following can give you some hints.
    Dynamics 365 Business Central: Set up default ship-to addresses
     
    Thanks.
    ZHU

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 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans