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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Customer Prevented to choose Items at the level of SO

(0) ShareShare
ReportReport
Posted on by 47

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 

table 60150 "Xee Customer/Category Prevent"
{
    Caption = 'Customer / Category Prevention';
    DataClassification = ToBeClassified;

    fields
    {
        field(1; "Item Categ. Code"; Code[20])
        {
            Caption = 'Item Categ. Code';
            DataClassification = ToBeClassified;
            TableRelation = "Item Category";

        }
        field(2; Description; Text[100])
        {
            Caption = 'Description';
            DataClassification = ToBeClassified;
        }
        field(3; "Customer No."; Code[20])
        {
            Caption = 'Customer No.';
            DataClassification = ToBeClassified;
        }
        field(4; "Line No."; Integer)
        {
            Caption = 'Line No.';
            DataClassification = ToBeClassified;
        }
    }
and here I can fill what category is prevented to a certain customer.
The Level I am stuck on it at the moment is that I am getting the banned Category on the "Sales Order Subform" page 46
   trigger OnAfterGetRecord()
    var
        SalesHeader: Record "Sales Header";
        Customer: Record Customer;
        PreventedBrands: Record "Xee Customer/Category Prevent";

        i: Integer;
    begin
        i := 0 ;
        if BannedCategoryy.Count > 0 then begin

        for i := BannedCategoryy.Count() downto 1 do
            BannedCategoryy.RemoveAt(i);

        end;

        if SalesHeader.get(Rec."Document Type", Rec."Document No.") then;
        if Customer.get(SalesHeader."Sell-to Customer No.") then;

        PreventedBrands.SetRange("Customer No.", Customer."No.");

        if PreventedBrands.FindFirst() then
            repeat
                BannedCategoryy.Add(PreventedBrands."Item Categ. Code");


            until PreventedBrands.Next() = 0;




    end;
 
But I haven't found a way to make a filter that the user when he press on the (No.) or (description) fields the dropdown list will be already filtered.
  • Suggested answer
    YUN ZHU Profile Picture
    103,257 Super User 2026 Season 2 on at

    Hi, I don't think this needs to be customized, just use the Security Filter function.

    More details: https://yzhums.com/10133/

    pastedimage1685663250400v1.png

    pastedimage1685663304106v2.png

    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/

    pastedimage1685663443876v3.png

    Hope this helps.

    Thanks.

    ZHU

  • Ziyad Najami Profile Picture
    47 on at

    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.

  • Jun Wang Profile Picture
    8,220 Moderator on at

    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

  • Verified answer
    Tech-Lucky Profile Picture
    1,288 Moderator on at

     Ziyad Najami 

    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.

  • Suggested answer
    Ziyad Najami Profile Picture
    47 on at

    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;
            }

  • Tech-Lucky Profile Picture
    1,288 Moderator on at

    Great I update the above code for other community members thanks for your feedback

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 715 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 452 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 371 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans