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.
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;
**************************************
Hi, just an idea.
Create a new field in Purchase Line table, for example, "Purchase Price Item". Releated to Table Purchase Price (7012)
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
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
Hi, How about using Security Filters? This is a out-of-box feature in BC.
Hope this helps.
Thanks.
ZHU
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.
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
Please see this post for more info. I am not developer but looks like the suggested method worked.
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
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.
If it needs to be done through customization , could you please suggest how it can be done exactly to achieve this functionality?
Thanks
Sohail Ahmed
858
YUN ZHU
773
Super User 2025 Season 1
Mansi Soni
569