Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Custom Filter

Posted on by 2,382

I have some Text string in a variable and I have a filter field in a table . I want to check if My text variable come under filter criteria specified in table's filter field.

Example  Variable A := 'This is Text String'

Filter Field = '*This'

or

Filter Field = '*String' 

If my case was apposite I could have used setfilter. But I am confused in this case.

*This post is locked for comments

  • Verified answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Custom Filter

    hi,

    so you need the vice versa functionality. it can be done by regular expressions. Use following dotnet class:

    // variables

    RegEx | DotNet | 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.RegularExpressions.Regex

    regMatches | Boolean

    SampleText | Text

    // code

    regMatches := Regex.IsMatch(SampleText, "Table X"."Filter Text");

    regMatches is true, if sample text matches the filter crit. in "Filter Text".

    "Filter Text" should follow reg. expression syntax not sql filter syntax, e.g. '^This' for "should start with 'This' or 'string$' for "should end with 'string'.

    if you do not want to use nav/sql syntax in your expressions, then it's needed to replace the given symbols like * by the according symbols according the regex syntax.

  • NavTech Profile Picture
    NavTech 2,382 on at
    RE: Custom Filter

    I have a Table Lets say Table X with field. "Filter Text".

    I will fill filter string in this field. "Filter Text". Eg.  *String* or String1|String2 or *String.

    I have a Text variable which contains a simple text.

    I want to check if Text variable comes under filter criteria specified in field. "Filter Text" of Table X

  • keoma Profile Picture
    keoma 32,675 on at
    RE: Custom Filter

    please describe more clearly, what you want to do.

  • NavTech Profile Picture
    NavTech 2,382 on at
    RE: Custom Filter

    yes you are right.The solution you given is correct.But can I do it without using temp Table.

  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Custom Filter

    for usage of setfilter try this:

    // Filter by 'This*': all text values STARTING with 'This'

    Rec1.SETFILTER(TextField,'This*');

    // Filter by '*This*': all text values ENDING with 'This'

    Rec1.SETFILTER(TextField,'*This');

    // Filter by '*String': all text values ending with 'String'

    Rec1.SETFILTER(TextField,'*String');

  • Suggested answer
    RE: Custom Filter

    If I understood correctly, "*This" should return false and "*String" should return true.

    "*This" does not work, because your text string does not end with This.

    If that is true, simply insert your text string into a text field of an arbitrary temporary table (create a new record and insert it), and then filter on this table field using:

    YourTempRec.SETFILTER(TheTempTableTextField,ValueFromYourFilterField);


    Then check whether a record could be found or not.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans