Hi, you can use OnLookup/OnDrillDown trigger on the field . As you only need to show contact for the same customer , you need to get the main contact first from Contact Business Relation , once you get it filter contact based on same company no.
Sample code as below :
field(Test;"Ship-to Contact")
{
ApplicationArea = All;
trigger OnLookup(Text : Text) : Boolean;
var
ContactBusRel : Record "Contact Business Relation";
Contact : Record Contact;
begin
ContactBusRel.Reset;
Contact.Reset;
ContactBusRel.SetRange("Link to Table",ContactBusRel."Link to Table"::Customer);
ContactBusRel.SetRange("No.",Rec."Sell-to Customer No.");
if ContactBusRel.FindFirst then begin
Contact.SetRange("Company No.",ContactBusRel."Contact No.");
if Page.RunModal(PAGE::"Contact List",Contact) = ACTION::LookupOK then begin
Rec."Ship-to Contact" := Contact."No.";
end;
end;
end;
}