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

(4) ShareShare
ReportReport
Posted on by 126
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.
  • Verified answer
    ME-31032107-0 Profile Picture
    126 on at
    Sales Order Bill-to Address Code Customization
    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.
  • ME-31032107-0 Profile Picture
    126 on at
    Sales Order Bill-to Address Code Customization
    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;
    }
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    16,318 Super User 2025 Season 1 on at
    Sales Order Bill-to Address Code Customization
    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.).
     
  • Suggested answer
    Jainam M. Kothari Profile Picture
    7,921 on at
    Sales Order Bill-to Address Code Customization
    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
    Suresh Kulla Profile Picture
    47,688 on at
    Sales Order Bill-to Address Code Customization
    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.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 374 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 247

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 231 Most Valuable Professional

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans