Skip to main content

Notifications

Announcements

No record found.

Business Central forum
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)*

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?

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,215 Moderator on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    hi

    try this

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

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

    check my answer if it helped you, thanks

    DAniele

  • Dev-Master Profile Picture
    Dev-Master 65 on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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.

  • Manthan Thesiya Profile Picture
    Manthan Thesiya 59 on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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
    Dev-Master 65 on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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?

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 58,861 Super User 2024 Season 2 on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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
    Dev-Master 65 on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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
    Nitin Verma Profile Picture
    Nitin Verma 20,995 Moderator on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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
    Dev-Master 65 on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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
    Mohana Yadav Profile Picture
    Mohana Yadav 58,861 Super User 2024 Season 2 on at
    RE: The length of the string is 22, but it must be less than or equal to 20 characters. Value: @*DS-2CD2132F-IW(4MM)*

    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)*

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,126 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans