Hello Experts,
I have been assigned a task that prevent Items at the level of SO Lines to appears (filter them) according to the (Item category Code) for more explanation I have made a table
Hello Experts,
I have been assigned a task that prevent Items at the level of SO Lines to appears (filter them) according to the (Item category Code) for more explanation I have made a table
Great I update the above code for other community members thanks for your feedback
Thank you for your help. The way has worked with me just want to add a little bit that at the level of the onLookup field(Sell-to Customer No). is empty. So I have got it from the Sales Header
modify("No.") { trigger OnLookup(var Text: Text): Boolean Var RecBLockedItem: Record "Xee Customer/Category Prevent"; // just an example; BlockedCategoryFilter: text; RecItem: Record Item; SalesHeader: Record "Sales Header"; Customer: Record Customer; begin if SalesHeader.Get(Rec."Document Type", Rec."Document No.") then; if Customer.Get(SalesHeader."Sell-to Customer No.") then; RecBLockedItem.reset(); RecBLockedItem.Setrange("Customer No.", Customer."No."); IF RecBLockedItem.findset() then repeat IF BlockedCategoryFilter <> '' then BlockedCategoryFilter := BlockedCategoryFilter ' &<>' RecBLockedItem."Item Categ. Code" else BlockedCategoryFilter := '<>' RecBLockedItem."Item Categ. Code"; until RecBLockedItem.Next() = 0; RecItem.Reset(); RecItem.SetFilter("Item Category Code", BlockedCategoryFilter); IF Page.RunModal(0, RecItem) = Action::LookupOK then Rec.Validate("No.", RecItem."No."); end; }
For this, You need to do the Following :
1.) Create a Table as you already mentioned which contains Customer No. and the Restricted Item Category Codes.
2.) Extend the Sales order Subform and write the Code on the Lookup Trigger of the item No field Like Bellow :
modify("No.") { trigger OnLookup(var Text: Text): Boolean Var RecBLockedItem: Record "Xee Customer/Category Prevent"; // just an example; BlockedCategoryFilter: text; RecItem: Record Item; begin if SalesHeader.Get(Rec."Document Type", Rec."Document No.") then; if Customer.Get(SalesHeader."Sell-to Customer No.") then; RecBLockedItem.reset; RecBLockedItem.Setrange("Customer No.", Customer."No."); IF RecBLockedItem.findset() then repeat IF BlockedCategoryFilter <> '' then BlockedCategoryFilter := BlockedCategoryFilter ' &<>' RecBLockedItem."Item Categ. Code" else BlockedCategoryFilter := '<>' RecBLockedItem."Item Categ. Code"; until RecBLockedItem.Next() = 0; RecItem.Reset(); RecItem.SetFilter("Item Category Code", BlockedCategoryFilter); IF Page.RunModal(0, RecItem) = Action::LookupOK then validate("No.", RecItem."No."); end; }
Note: doing this code on the Lookup Trigger has one disadvantage it will disable the table relation for all the types like G/L account, Fixed Assets, etc so you need to do the lookup code for the other available type as well.
Please Verify this answer if this was helpful.
another way to approach this is to set up a workflow that triggers on such items so user won't mistakenly create SO for those
Mr. ZHU
Thank you for you replay first of all, I think I haven't explained clearly what I want,
So, let's say the scenario is as that Customer C-001 is prevented to choose Item that have Item Category Code ['FOOD'] and C-002 is prevented from ['Drinks']. So, my knowledge about permission set is that it is on the level of the User,
and I don't want that, I want if I choose in Sales Header C-001 then when I am selecting Item No.,
I want the list to be filtered from the Item Whose category is Food and if I change to C-002 then the Items List will be filtered from the Item whose category is drinks.
Hi, I don't think this needs to be customized, just use the Security Filter function.
More details: https://yzhums.com/10133/
In addition, the No. field on the Sales Line is achieved through the TableRelation attribute, which has some restrictions if customized.
More details: Can we extend TableRelation Property through a table extension??? (Yes, But…): https://yzhums.com/26939/
Hope this helps.
Thanks.
ZHU
André Arnaud de Cal... 291,391 Super User 2024 Season 2
Martin Dráb 230,445 Most Valuable Professional
nmaenpaa 101,156