Problem searching for string containing ampersand

Jay2007Jay2007 Member Posts: 50
Hi there,

I have a form with a search field on it used to search on the Item description field. When the user enters text in this field I use the following code to search for any item descriptions that contain this text within it :-

SearchStr := '@*'+"Search Field"+'*';
Item.SETFILTER( Description, Search Field );

The problem with this is that the search yields nothing if the search string contains an ampersand (&) in it.

Does anyone have a workaround for this?

Thanks,

Jay

Answers

  • ara3nara3n Member Posts: 9,256
    change the ampersand to question mark.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    I just retested it in sql and native and it works fine . In cronus it returned 1 record.

    searchstr := '*@n&G*';
    customer.setfilter("name",searchstr);
    message(format(customer.count));
    


    Then changed it to
    searchstr := '*@n&g*';
    customer.setfilter("name",searchstr);
    message(format(customer.count));
    

    It didn't work on native, but worked fine on sql.

    So you could use "Search Description" field and make the searchstr all UPPERCASE. Or create a new field and make it Code type and copy of description and search on that.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSterDenSter Member Posts: 8,305
    If you have a collation that is not case sensitive though it should return the same.
  • PeterDPeterD Member Posts: 66
    From the user interface (3.60) I can use the filter '@*&*' to find all occurences with the ampersand. But I have to include both single quotes for that! Without them every record is returned.

    So maybe if you try to include the single quotes in your SearchStr?
  • Jay2007Jay2007 Member Posts: 50
    That works perfectly Peter. Thanks very much for that !! :mrgreen:
Sign In or Register to comment.