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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

(0) ShareShare
ReportReport
Posted on by 65

Hi I am stuck in an issue, I am trying to apply SetFilter function on the item record to search this item with name: DS-2CD2132F-IW(4MM).
When i apply filter on it, the text looks like @*DS-2CD2132F-IW(4MM)*. The setfilter function throws exception because the length of No. field in item table is Code[20] and the search text length become 22.

The code is here.

searchTxt := StrSubstNo('@*%1*', itemNo);
itemRec.SetFilter("No.",'%1', searchTxt);

if itemRec.FindSet() then begin
UnitPrice := itemRec."Unit Price";
end

I get this exception: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

I am interested to apply the filter whatever the length of the field in table is.

How can i solve this issue to filter the record?

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at

    You have to reduce the ItemNo filter value to 18 in that case as there will be no other items even if you set *DS-2CD2132F-IW(4MM)*

  • Dev-Master Profile Picture
    65 on at

    Hi thank you for your response. But it might be the scenario when there is another item with the same name but it might be possible the last two characters of the item name are change in this this logic fails. i already tried it but it didn't work with another item whose last two characters were just different.

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    You can try as per below just put "*" where you seems that character might be different

    @*DS-2CD2132F-IW(4*MM*)*

  • Dev-Master Profile Picture
    65 on at

    No i cannot do like this because there are more than 25000 products and all can have same character to some specific length lets say 5 products can have 15 characters same and then last 5 characters can be different. In other case the product can have 17 characters same and 3 characters can be different in start or last.

    So i want it to be generic.

  • Suggested answer
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at

    then you have to check itemno string length first and if it is 20 then apply the filter as it is.

    If less than 18 then apply the @*%1* etc.

  • Dev-Master Profile Picture
    65 on at

    Yes i tried it but it was not of my use case. cannot i make it waork like if we use the builtin filter option from the page?

  • Manthan Thesiya Profile Picture
    59 on at

    Hello..

    it bit strange that you are getting error for Special character '('.

    But i tried with below code:

           searchTxt: Text;

       begin

           searchTxt := StrSubstNo('@*%1*', 'DS-2CD2132F-IW-14MM'); // instead of DS-2CD2132F-IW(4MM)

           Rec.SetFilter(Rec."No.", searchTxt);

    End;

    And its totally working fine in my system. (Currently using version Business central 21.3)

    First of all as per my suggestion remove Special characters in Item name. because it will cause error in future Also.

    Item-list-filter.png

    Don't forget to help the community by verifying the answer if your question has been answered.
    It will let others know that the topic has verified answer.

  • Dev-Master Profile Picture
    65 on at

    Thank you for your response. No my problem is still there i cannot remove the special characters from the text. That's why it is still tricky to handle this scenario.

  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    hi

    try this

    searchTxt := STRSUBSTNO('*%1*', itemNo);

    Customer.SETFILTER("No.",'@%1', searchTxt);

    check my answer if it helped you, thanks

    DAniele

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 2,664

#2
YUN ZHU Profile Picture

YUN ZHU 960 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans