Options

Special Characters in Filter String

jimmyfjimmyf Member Posts: 103
Is it possible to include special characters, e.g. * or & in a filter string?

Some Customer and Vendor names have these characters and I cannot find them when doing a SETRANGE or SETFILTER in C/AL.

CustNameFilter := '@' + CustName;
recCust.INIT;
recCust.SETFILTER(recCust.Name,CustNameFilter);


Thanks

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,090
    Some tricks:
    use SETRANGE. In this case the string is taken as is.
    If you use SETFILTER, best is to replace those chars with '?' which means any character. So it is not perfect, but better I didn't find.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    vaprogvaprog Member Posts: 1,125
    See the following two posts:
    Error"The filter "Cert(A)"is not valid.Did not expect a '('"
    Filtering question

    Note: The @ needs to go to the value parameter, not the FilterString.
    CustNameFilter := '@' + CustName;
    recCust.INIT;
    recCust.SETFILTER(recCust.Name,'%1',CustNameFilter);
    
  • Options
    jimmyfjimmyf Member Posts: 103
    Hi there
    Thanks for replying. I coukd not get the SETRANGE to work however replacing the & and * characters with a ? character and using SETFILTER worked perfectly.

    Thanks
  • Options
    vaprogvaprog Member Posts: 1,125
    jimmyf wrote:
    I coukd not get the SETRANGE to work
    SETRANGE would solve your problem with & and *, but does not treat @ as case insensitive indicator, but treats this character literally too.
    Did you try my suggestion of using %1 and value parameters with SETFILTER? It has the advantage of being simpler to implement and not creating ambiguities.
  • Options
    jimmyfjimmyf Member Posts: 103
    Hi there
    yes I used your suggestion and it worked perfectly.
    Thanks for your help :D
Sign In or Register to comment.