Hi there,
(Thank you very much for looking at my post)
At the PO Line record, you can select the item through the drop down at "No." field as shown in the screenshot below. The default behavior is to show you all Items in the system, and it is not filtered based on the selected Vendor in PO. I am writing AL codes using OnLookup() as shown below to filter items based on the selected vendor. The filter does work, and the code of RunModal() does work too. However, the problem is that when the user selects an item, the item will not be set into the PO Line record. In other words, the PO Line's "No." field remains as blank even if the user selects an item from the popup.
I would like to consult with you on how you solve this problem. And what is wrong in my AL codes below.
pageextension 50111 "Purchase Line Subform Ext" extends "Purchase Order Subform"
{
layout
{
// Alter the drop-down list to limit the list by the selected vendor of the Purchase Order
modify("No.")
{
trigger OnLookup(var Text: Text): Boolean
var
ItemRec: Record Item;
PurchaseHeader: Record "Purchase Header";
begin
if Rec.Type <> Rec.Type::Item then
exit(false); // Only apply to Item lines
// Get the header
if PurchaseHeader.Get(Rec."Document Type", Rec."Document No.") then begin
// Apply vendor filter
ItemRec.Reset();
ItemRec.SetRange("Vendor No.", PurchaseHeader."Buy-from Vendor No.");
end;
if PAGE.RunModal(PAGE::"Item List", ItemRec) = ACTION::LookupOK then
Rec.Validate("No.", ItemRec."No."); <== I am expecting this line to update the "No." field in PO Line, but it did not!!
exit(true);
end;
}
}
}