There seems to be a lot of old material around, but none which makes it absolutely clear how to obtain the new best practice of showing a field with both the code and name of a vendor, customer or contact and supporting a lookup from either field.
I tried to look into the source code on the Vendor and Sales Order page, but enough detail is hidden in the definition that I can't quite nail it.
I have a new table and page called Container Entry. These need to refer to both a Vendor and Customer.
Looking at some old recommendations I tried to add to the OnLookup trigger event of the Vendor Name field, but it doesn't work. Code below.
Here is an excerpt from the Table Definition.
field(50182; "No."; Code[20]) { DataClassification = CustomerContent; trigger OnValidate() BEGIN IF "No." <> xRec."No." THEN BEGIN PurchaseSetup.GET; NoSeriesMgt.TestManual(PurchaseSetup."Order Nos."); "No. Series" := ''; NoSeriesMgt.SetSeries("No."); END; end; } field(50184; "No. Series"; Code[20]) { DataClassification = CustomerContent; TableRelation = "No. Series"; ValidateTableRelation = true; } field(50204; "Vendor No."; Code[20]) { DataClassification = CustomerContent; TableRelation = Vendor; ValidateTableRelation = true; } field(50213; "Vendor Name"; Text[100]) { Caption = 'Vendor Name'; TableRelation = Vendor.Name; trigger OnValidate() var VendorRec: Record Vendor; begin "Vendor No." := VendorRec.GetVendorNo("Vendor Name"); end; }
Here is an excerpt from the page definition:
field(Shipper; "Vendor No.") { ApplicationArea = All; } field("Vendor Name"; "Vendor Name") { ApplicationArea = All; TableRelation = Vendor.Name; Lookup = true; LookupPageId = "Vendor List"; }
Here is what it looks like.
The vendor number drop down works fine. However, there is no active lookup on the Vendor Name. Clicking it does nothing and I'm not sure how it will then update the
Vendor Number field at the same time. I have used a code unit on the function to do that.
Thanks - so simple and works perfectly.
Please change your field properties to below :
field(50204; "Vendor No."; Code[20])
{
DataClassification = CustomerContent;
TableRelation = Vendor;
ValidateTableRelation = true;
trigger OnValidate()
var
VendorRec: Record Vendor;
begin
VendorRec.Get("Vendor No.");
"Vendor Name" := VendorRec."Name";
end;
}
field(50213; "Vendor Name"; Text[50])
{
Caption = 'Vendor Name';
TableRelation = Vendor;
ValidateTableRelation = false;
trigger OnValidate()
var
VendorRec: Record Vendor;
begin
VALIDATE("Vendor No.",VendorRec.GetVendorNo("Vendor Name"));
end;
}
On the page extension you can remove the table relation and lookup properties.