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...
Unanswered

Apply Filter Text to TableRelation?

(0) ShareShare
ReportReport
Posted on by 10

Hi All,

This is the scenario. 

I am working on this extension where a user is able to pick a product category to filter a dropdown of Items.
Because this user is also able to select a parent category I wrote a CodeUnit that takes in a Item Category and returns a Text containing itself and all of the sub categories:

Example:

The table I am working with is my own table "Project Item"

User chose item category: 'Projection Surfaces'
The Codeunit returns: 'Projection Surfaces|Projection Fabrics|Projection Boards|Projection Screens'
This response it put in the field Rec."Category Filter" where Rec is a "Project Item" and "Category Filter" is a field of type Text[100.

I would like to apply this filter to the TableRelation of the ProjectItem."No." field.
I tried this:

field(4; "Item No."; Code[20])
{
    Caption = 'Item No.';
    DataClassification = CustomerContent;

    TableRelation = if ("Category Filter" = filter(<> '')) Item where("Item Category Code" = field("Category Filter"))
    else
    Item;

}
Now this is not working like I want it to.
When a user selects an item category which results in only that item category being returned such as "Projection Screens" then the filter is working and filters the "No." field correctly. However, when the user chose an item category that has child categories and I end up with a filter like  'Projection Surfaces|Projection Fabrics|Projection Boards|Projection Screens' I get errors about lengths (65) are exceeding the Code[20 length. I get this, but how can I correctly apply this text filter to a table relation?

N.B.
I did manage to sort this out using custom OnLookup logic but it seems counter intuitive writing this custom logic because it felt I was so close to the solution before.
Thanks for taking the time to help me out here!
T.
I have the same question (0)
  • Lars Lohndorf-Larsen Profile Picture
    on at
    RE: Apply Filter Text to TableRelation?

    Hi, good question.

    I would have suggested to use Filter instead of Field, like this:

    TableRelation = if ("Category Filter" = filter(<> '')) Item where("Item Category Code" = filter("Category Filter"));
    But quick tests here seems that that doesn't work either. I can set a filter like this in the old dev client:
    IF (Category Filter=FILTER(<>'')) Item WHERE (Item Category Code=FILTER(CATEGORY FILTER))
    So I wonder if the standard application is using anything like this somewhere, then that should show how to do it. Otherwise you may have to code the OnLookup trigger like you say. Also I look forward to hearing other suggestiopns.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans