SETFILTER using a String with integers

McMercyMcMercy Member Posts: 7
Hello!

How do I have to code the following filter:

IF TableInput.FIND ('-') THEN BEGIN
REPEAT
strFilter := strFilter + Format( TableInput.TableID) + '|';
UNTIL TableInput.NEXT = 0;
END;

SETFILTER("Object ID",'%1',strFilter);

The Filter should filter by Objekt ID which is an integer, of course strFilter is a string with a list of integers linked with |. Navision refuses to do this, what is the correct synthax?

Thanks

Comments

  • garakgarak Member Posts: 3,263
    setfilter("Object ID", strFilter);

    Note: with your loop, the variable strFilter ends with a | <- this you must eleminate.

    Regards
    Do you make it right, it works too!
  • DaveTDaveT Member Posts: 1,039
    Hi McMercy,

    Look to me as if the filter is build as 1|2|3| the problem is the last |

    to remove the last | use

    strFilter := copystr( strfilter, 1, strlen(strfilter) -1 );

    How this helps

    PS Welcome to Mibuso :mrgreen:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • DaveTDaveT Member Posts: 1,039
    garak wrote:
    setfilter("Object ID", strFilter);

    Note: with your loop, the variable strFilter ends with a | <- this you must eleminate.

    Regards

    Dam it - Beaten again #-o - you Germany are far too efficent :D
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • garakgarak Member Posts: 3,263
    sorry dave: the first problem is the way he use setfilter

    the thierd parameter, the value, must have the same datatype like the field which is filtered. The filtered field is from type integer. But the value is text so the compiler would tell this.
    To solved this, you can put your filterconsturct into the second parameter. Instead of
    setfilter(YourFieldIsInteger,'%1|%2|%3',1,4,6);
    

    you can also write
    setfilter(YourFieldIsInteger,'1|4|6);
    

    but not
    setfilter(YourFieldIsInteger,'%1','1|4|6');
    

    the second problem in this code is, see in the first post, that the variable strFilter ends with a | <- the last pipe must be eleminated

    regards
    Do you make it right, it works too!
  • garakgarak Member Posts: 3,263
    no comment ;-) :whistle:
    Do you make it right, it works too!
  • DaveTDaveT Member Posts: 1,039
    :oops: missed the setfilter problem - just like the compiler I stopped when I hit the first problem :D
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • David_CoxDavid_Cox Member Posts: 509
    Nearly There but as said the last pipe "|" is a problem, but the solution is simple.
    1st problem there might be only one record, so we have to code for this.
    2nd the Pipe "|" has to come before the the string, but not for the First Record, so we add a counter, and change the string based on its value.
    J := 0;
    IF TableInput.FIND ('-') THEN 
       REPEAT 
           j := j + 1;
           IF j := 1 THEN
              strFilter := Format( TableInput.TableID)
           ELSE
              strFilter := strFilter + '|' + Format( TableInput.TableID); 
       UNTIL TableInput.NEXT = 0; 
    

    Hope this helps! :)

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • andy76andy76 Member Posts: 616
    Hello,

    is that possible to filter...constructing a string as the previous... but with <> (not equal ) from a list?

    SETRANGE("Purch.Order Line No.", '<>%1', myString) ?
    with my String = 'A|B|C...'


    Or which is the right syntax?

    myString = '<>A|<>B|<>C ...'

    Thank you
  • kinekine Member Posts: 12,562
    You need to use AND between each part. it means '<>A&<>B&<>C' else it will be true in all cases...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • BeliasBelias Member Posts: 2,998
    kine wrote:
    You need to use AND between each part. it means '<>A&<>B&<>C' else it will be true in all cases...
    unless a=b=c :mrgreen::mrgreen::mrgreen:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.