Options

Strange behavior in SETFILTER

EgnazEgnaz Member Posts: 111
Hi there,

I wanted to use a simple SETFILTER like this SETFILTER("No.",'%1*',MyNo)
But this filter won't work as intendet. The result from ERROR(GETFILTERS) is Filter: "No."=*
I had to a workaround to get it working for me. SETFILTER("No.",'%1',MyNo + '*') works and I get my correct filter.

Tested on NAV2009 SP1.

Any ideas why it won't work?

Greetz
egnaz

Answers

  • Options
    ShedmanShedman Member Posts: 194
    Hmmm ... I had the same problem last week. Found the solution in the forum somewhere.

    But you could try SETFILTER("No.",'%1','*' + MyNo)
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
  • Options
    EgnazEgnaz Member Posts: 111
    Egnaz wrote:
    I wanted to use a simple SETFILTER like this SETFILTER("No.",'%1*',MyNo)

    Yes, tried it.
  • Options
    kinekine Member Posts: 12,562
    Thereis one old bug since version 2.x, when the %1 in the string is not replaced with the parmeter when there is something behind this placeholder. I have already described it somewhere... :-k
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    EgnazEgnaz Member Posts: 111
    After some research I found the KB article 951233
    Official the bug is since NAV 4:
    SYMPTOMS
    Consider the following scenario. You use the C/AL command SETFILTER in Microsoft Dynamics NAV 4.0. The filter includes a wildcard character and a field replacement. For example, the wildcard character is an asterisk or a question mark. In this scenario, the filter may not be applied correctly.
    CAUSE
    This problem occurs because Microsoft Dynamics NAV 4.0 cannot handle wildcard characters when it applies a filter and must perform a field replacement action in the filter.
    WORKAROUND
    To work around this problem, separate the field replacements into a different step. For example, you use the following command:
    Rec.SETFILTER("No.",'%1*','100');
    
    Note You can use %N as a field replacement. N represents a number.

    Microsoft Dynamics NAV 4.0 replaces %1 with 100. Therefore, the command resembles the following command:
    Rec.SETFILTER("No.",'100*');
    
    If you change the C/AL code to have specific filters as in this example, the SETFILTER command works as expected.

    To avoid the problem that is described in the "Symptoms" section, make sure that you do not combine field replacements (%) with wildcard characters. If you must use such a combination, convert the filter into a string. Then, use the string as the filter instead.

    For example, you use the following command:
    Item.SETFILTER("No.",'%1*','100');
    
    Change the command to use the string as follows:
    TempString := STRSUBSTNO('%1*','100');
    Item.SETFILTER("No.",TempString);
    

    Thanks to all.

    Hopefully the "bug" will be fixed in one of the next releases.

    Regards,
    Egnaz
  • Options
    Johannes_NielsenJohannes_Nielsen Member Posts: 206
    Ohhh my g0d :sick:
    Wheres that smiley with the wall - ohh there it is
    ](*,) ](*,)

    I've been dealing with this little thing for half the day, thought I was dumb :)

    5.0 it has'nt been fixed, well now I know!
    Best regards / Venlig hilsen
    Johannes Sebastian
    MB7-840,MB7-841
Sign In or Register to comment.