Skip to main content

Notifications

Community site session details

Community site session details

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

Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

(0) ShareShare
ReportReport
Posted on by

I am new Dynamics BC and still learning my way around BC tables and pages and extensions. My query is :-

On Purchase Order form when Vendor is selected , i want items ("No." field lookup) in Items List on Purchase Order Line to be filtered with Purchase price list items maintained for that Vendor selected on purchase order header. Currently it shows all items in Items list irrespective of Vendor selected. Please suggest a exact approach of how can i do this or any help would be appreciated.

pastedimage1653065494386v2.png

pastedimage1653065372259v1.png

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    Hi All ,

    Thanks for all your help and suggestions. After so much brainstorming i was actaully able crack the solution and was able to achieve my requirement.

    Below i have highlighted the code ,  where i was able to fetch items from pricelist based on vendor and then fitlered Itemlist on Purchase Order line with retrieved items from pricelist.

    **************************************

    trigger OnLookup(var Text: Text): Boolean

               var

                   PurchHeaderRec: Record "Purchase Header";

                   Item: Record Item;

                   ItemList: Page "Item List";

                   ItemChargesRec: Record "Item Charge";

                   FixedAssetRec: Record "Fixed Asset";

                   GLAccountRec: Record "G/L Account";

                   StdTextRec: Record "Standard Text";

                   ResourceRec: Record "Resource";

                   PriceListlineRec: Record "Price List Line";

                   ProductNoFilter: Text;

               begin

                   CASE Rec.Type OF

                       Rec.Type::" ":

                           BEGIN

                               StdTextRec.Code := Text;

                               IF PAGE.RUNMODAL(0, StdTextRec) = ACTION::LookupOK THEN BEGIN

                                   Text := StdTextRec.Code;

                                   EXIT(TRUE);

                               END;

                           END;

                       Rec.Type::"Charge (Item)":

                           BEGIN

                               ItemChargesRec."No." := Text;

                               IF PAGE.RUNMODAL(0, ItemChargesRec) = ACTION::LookupOK THEN BEGIN

                                   Text := ItemChargesRec."No.";

                                   EXIT(TRUE);

                               END;

                           END;

                       Rec.Type::"Fixed Asset":

                           BEGIN

                               FixedAssetRec."No." := Text;

                               IF PAGE.RUNMODAL(0, FixedAssetRec) = ACTION::LookupOK THEN BEGIN

                                   Text := FixedAssetRec."No.";

                                   EXIT(TRUE);

                               END;

                           END;

                       Rec.Type::"G/L Account":

                           BEGIN

                               GLAccountRec."No." := Text;

                               IF PAGE.RUNMODAL(0, GLAccountRec) = ACTION::LookupOK THEN BEGIN

                                   Text := GLAccountRec."No.";

                                   EXIT(TRUE);

                               END;

                           END;

                       Rec.Type::"Resource":

                           BEGIN

                               ResourceRec."No." := Text;

                               IF PAGE.RUNMODAL(0, ResourceRec) = ACTION::LookupOK THEN BEGIN

                                   Text := ResourceRec."No.";

                                   EXIT(TRUE);

                               END;

                           END;

                       Rec.Type::Item:

                           BEGIN

                               PurchHeaderRec.RESET;

                               PurchHeaderRec.SETRANGE("No.", Rec."Document No.");

                               IF PurchHeaderRec.FINDFIRST THEN;

                               Item.RESET;

                               PriceListlineRec.Reset;

                               PriceListlineRec.SetRange("Source No.", PurchHeaderRec."Buy-from Vendor No.");

                               if PriceListlineRec.IsEmpty() then BEGIN

                                   Item.SetRange("No.");

                               end

                               else begin

                                   IF PriceListlineRec.FINDSET THEN BEGIN

                                       REPEAT

                                           ProductNoFilter += PriceListlineRec."Asset No." + '|';

                                       UNTIL PriceListlineRec.NEXT = 0;

                                   END;

                                   ProductNoFilter := ProductNoFilter.Remove(ProductNoFilter.LastIndexOf('|'));

                                   Item.SetFilter("No.", ProductNoFilter);

                               end;

                               Item."No." := Rec."No.";

                               ItemList.SETTABLEVIEW(Item);

                               ItemList.LOOKUPMODE(TRUE);

                               IF Page.RUNMODAL(0, Item) = ACTION::LookupOK THEN BEGIN

                                   Text := Item."No.";

                                   EXIT(TRUE);

                               END;

                           end;

                   end;

               end;

    **************************************

  • Suggested answer
    YUN ZHU Profile Picture
    83,072 Super User 2025 Season 1 on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    Hi, just an idea.

    Create a new field in Purchase Line table, for example, "Purchase Price Item". Releated to Table Purchase Price (7012)

    pastedimage1653348517636v1.png

    When the Type on the line is Item, use this new field to select Item, and the standard No. field will not be editable directly.
    When this new field is validated, automatically fill in Item No. in standard No. field
    When Type is others, such as G/L account, Item charge....Users still use the standard No. field.

    I think this is a relatively simple and easy way to implement, I hope it can give you some inspiration.

    Thanks.

    ZHU

  • Community Member Profile Picture
    on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    Hi Zhu , i dont think that would serve my requirement as i need to filter Item list on Purchase order line with Purchase price list items. Also i dont want to create this separate permission set and then apply to various users. Can you please suggest if this can be done through AL extensions and if yes how exactly would be the approach.

    Thanks

  • Suggested answer
    YUN ZHU Profile Picture
    83,072 Super User 2025 Season 1 on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    Hi, How about using Security Filters? This is a out-of-box feature in BC.

    https://yzhums.com/10133/

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,025 Moderator on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header
    [quote user="Adeel Ansari"]

    If it needs to be done through customization , could you please suggest how it can be done exactly to achieve this functionality?

    Thanks

    [/quote]

    I would recommend that you work together with your partner so have this solved in the best possible way. They can both suggest a way to do it and assist you with writing the AL code needed.

  • Suggested answer
    JAngle Profile Picture
    95 on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    This is an elegant approach that will give you more control over what page/table you take the user to. In your case it’s the purchase price list. Otherwise I think you would have to add a new field which does as you need and hide the standard if it’s an item type line. Then validate it when you use your new field

  • Suggested answer
    MahGah Profile Picture
    15,443 on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    Please see this post for more info. I am not developer but looks like the suggested method worked.

    community.dynamics.com/.../577101

  • Community Member Profile Picture
    on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    Yes i am aware about AL programming and extensions and have already learned pretty much. So yes i believe i would require to write code for customization to achieve this. I just need exact approach step by step how to achieve this .

    Thanks

  • Suggested answer
    MahGah Profile Picture
    15,443 on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    Do you want to write a code and create extension or your partner? If you like to write a code then you need to learn AL and development. You can watch this series of video www.youtube.com/watch  or  see this  docs.microsoft.com/.../

    if you want to ask your partner than my only suggestion is limit Item Reference to show only the vendor on PO header. this way you have Item No just in case if you want to select other items not related to that vendor.

  • Community Member Profile Picture
    on at
    RE: Populate items from Purchase price list into Item list on Purchase order line based on Vendor selected on Purchase header

    If it needs to be done through customization , could you please suggest how it can be done exactly to achieve this functionality?

    Thanks

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 858

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 569

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans