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;
}