Options

SETFILTER problem

garychickgarychick Member Posts: 34
Hi ALL,

I have an error when I used SETFILTER:
Item.SETFILTER(Item.Description, '70-HK-(W1)');

DO anyone know how to solve it?

Thanks!

Comments

  • Options
    saikiransaikiran Member Posts: 22
    Dear Gary,

    I Don't know what version of Navision you are using or where exactly you have written this code or what error message you have received.

    Still, I think you have made a fundamental mistake in the syntax of your code.

    The syntax should be:
    Item.SETFILTER(Description, '70-HK-(W1)');

    Check it out. It might help.
  • Options
    andreofandreof Member Posts: 133
    what's the error?
    Andre Fidalgo
    My world: Dynamics NAV,SQL and .NET

    CEO at Solving Dynamics
    http://www.solvingdynamics.com
  • Options
    garychickgarychick Member Posts: 34
    I think the issue is related to the '('. I found that it is not possible to put a '(' ot ')' in the filter.

    Does anyone know why?
  • Options
    saikiransaikiran Member Posts: 22
    Hi,

    I think the ')' in your Item Description is being taken as the end of the syntax of the setfilter function.
    That's why the error is occurring. I am not sure.
  • Options
    andreofandreof Member Posts: 133
    That's impossible, it's between ' ' so it's text. The problem is when applying the filter. You can't use '(' or ')'
    Andre Fidalgo
    My world: Dynamics NAV,SQL and .NET

    CEO at Solving Dynamics
    http://www.solvingdynamics.com
  • Options
    bestianhowbestianhow Member Posts: 120
    Hi Gary,
    Maybe u can try to use coding below:
    Item.SETFILTER(Item.Description,'%1' '70-HK-(W1)');
    




    Thank you,
    Kok Keong
  • Options
    bestianhowbestianhow Member Posts: 120
    Sorry Gary,
    The previous coding got problems. u just ignore it.
    Below is the correct coding

    Item.SETFILTER(Item.Description,'%1','70-HK-(W1)');
    
  • Options
    garychickgarychick Member Posts: 34
    Hi bestianhow,

    It works!

    Thanks!
  • Options
    kinekine Member Posts: 12,562
    Second and more used is
    Item.SETRANGE(Description,'70-HK-(W1)');
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    DenSterDenSter Member Posts: 8,304
    I always do:
    Item.SETRANGE(Description,'=%1','70-HK-(W1)');
    
    Makes me think about what exactly I need to do. So in this case I want to set an 'equal' filter, so I explicitly set it like that. Never failed me once.
  • Options
    eromeineromein Member Posts: 589
    But....

    Are you actually setting that filter? Or are you setting a filter usering a variable that could contain that value?

    Never code "hard" filters like that... right?
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • Options
    DenSterDenSter Member Posts: 8,304
    No of course not, you usually pass a parameter into the code. If I can help it at all I don't hard code filters.

    So, the actual code would be like:
    Item.SETRANGE(Description,'=%1',FilterValue);
    
    Where FilterValue is a variable with the filter criteria in it.
Sign In or Register to comment.