setting filter on TableBox or on a SubForm

jks
jks Member Posts: 277
Hi all,

I want to do following but do not know how could I achieve it:
I have one table containing data in following format

No.
JS11
J___
_S__
__1_
ABCD
___D

Now conside Customer card in Navision. On it I want to display only those values from the above table which matches with the current customer.
i.e if my customer is JS13 then from above table J___, _S__, __1_ values should be displayed on it.

So how could I set the filter in above manner? Will it be possible to use Table Box for this or I have to use a SubForm? Will it be possible to directly set the properties of the control and do not need to do any coding?

Thanks for any help.

Comments

  • girish.joshi
    girish.joshi Member Posts: 407
    It is possible to create such a filter, but its a little fragile.

    The simplest approach, and the most fragile, is to build a filter string.

    the code is something like (I haven't tested this, but hopefully you get the general idea):
    filtertoken := '' ; 
    filterstring := '' ;
    for i:= 1 to strlen(customer.no) do begin
      filtertoken := padstr('','_', 1-i) + DummyText."No"[i] + padstr('','_', strlen(customer,"no.") - i )   //not sure if this syntatically correct, you may have to do a copystr to get the ith char
      if filterstring <> '' then 
        filterstring := filterstring + '|' + filtertoken
      else 
        filterstring := filtertoken
    
    end ;
    

    This is fairly dangerous code... lots of potential problems here. Not the least of which is that there is a limit to the number of characters that can be in a filterstring... its something like 250, so that puts an upper limit of the length of your customer no's to abotu 15 characters.

    second of all, its very vulnerable to having bad characters in the customer no that will cause the filter string to break.

    finally, the code is generally not performant.

    but anyway, it can be done.

    If you are looking to match any character, and not specifically the underscore character, you can use ? in your search string to do match any single char.

    there are a couple of other clever ways to do this, btw. but I leave that to you.