Developers Knowledge Needed.. What / Why would someone use t

SteveSteve Member Posts: 81
I'm going through web service code and the previous developer uses (STRSUBSTNO('@%1', in every setfilter statement such as...

Contact.SETFILTER(Name, STRSUBSTNO('@%1', Name));
Contact.SETFILTER(City, STRSUBSTNO('@%1', City));

rather than

Contact.SETFILTER(Name, '%1' , Name);
Contact.SETFILTER(City, '%1' , City);


It maybe full well something I'm unaware of, but I'm looking for suggestions to why he may have used STRSUBSNO and @ in every setfilter in the navision system.


Any ideas? :-k
Steve

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    The @-sign is used to filter on values regardless of case (= case insensitive).
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    The @ makes it case insensitive.

    I'm always fighting this with setfilter too, simply because it is something you don't do each day (understatement).

    Just checked a customer database where I use the same construction, so I guess it makes sense. Although there might be me more roads that lead to rome.
  • SteveSteve Member Posts: 81
    so wouldn't this do the same thing..

    Contact.SETFILTER(Name, '@%1' , Name);
    Contact.SETFILTER(City, '@%1' , City);


    No need for STRSUBSNO ??
    Steve
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    That's what I said. I just remember that I poked around with this getting it to work, and my customers db has the same solution.

    It might work, it might have been a workaround in a certain version. My customer comes from 3.60 and runs on 2009 now.

    Have you tested both?
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    I think you need to write it like this to get it working:

    Contact.SETFILTER(Name, '%1' , '@' + Name);
    Contact.SETFILTER(City, '%1' , '@' + City);
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • vaprogvaprog Member Posts: 1,141
    Luc's version is the correct one.
    Contact.SETFILTER(Name, '%1' , '@' + Name);

    In the following construct, any characters in Name that have a special meaning in filter construction are use in that special meaning, so, if Name = 'Procter & Gamble', the construct will filter for a Name that is 'procter' (case insensitive) AND 'Gamble' (case sensiteve)
    Contact.SETFILTER(Name, STRSUBSTNO('@%1', Name));
    it is equal to
    Contact.SETFILTER(Name, '@'+Name));

    In the following construct, the string %1, which looks like a placeholder, will not be treated as such, but as the actual value. The last Name parameter is simply ignored and the filter filters for a literal '%1' (case insensitive, if that made sense)
    Contact.SETFILTER(Name, '@%1', Name);


    This is how I remember what SETFILTER will do:
    1. The String parameter (2nd parameter) is parsed as a filter expression into it's atomic parts (values and operators) where all the special symbols mentioned in the help topic Entering Criteria in Filters are treated as operators, except for @, *, ? which are treated as part of the value.
    2. Any value found in the preceding step that consist only of a placeholder will be replaced by the corresponding Value parameter (3rd and on) if such a parameter is given. Any special character within the Value is treated literally, except for @, *, ?.

    EDIT: I renounce the following statement. There seems to be no way to let the filter engine treat the characters @, *, ? literally.
    So, to be absolutely save, you'd need to write
    Contact.SETFILTER(Name, '@'''+Name+''''));
    
    (End of renouncement)
Sign In or Register to comment.