web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Filter the PO Line Items based on the selected Vendor in Purchase Order

(2) ShareShare
ReportReport
Posted on by 89
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;
}
}
}
I have the same question (0)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,137 Super User 2025 Season 2 on at
    Filter the PO Line Items based on the selected Vendor in Purchase Order
    Your issue happens because PAGE.RunModal doesn’t return the selected record automatically. Instead, create a page variable for the "Item List" page, apply your vendor filter to its record, run it with RunModal(), and then get the selected item from that page’s Rec to validate your PO Line’s "No." field. This way, the selected item properly updates the PO Line.
  • Suggested answer
    YUN ZHU Profile Picture
    92,218 Super User 2025 Season 2 on at
    Filter the PO Line Items based on the selected Vendor in Purchase Order
    Hi, ï½—hen you select, this purchase line has not been inserted into the database, so you must insert a line first and then validate, I think there will be no problem. Of course you'll need additional logic if the row already exists.
     
    Hope this can give you some hints.
    Thanks.
    ZHU
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 4,197

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,673

#3
Sumit Singh Profile Picture

Sumit Singh 2,907

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans