need help,filter field using variable

barubaru Member Posts: 27
customer.setfilter("no",10-001);
can i "no" declare using variable?
customer.setfilter(Var,10-001);

Comments

  • JohnJohn Member Posts: 43
    Why? Ik you can set the variable to a value you can write SETFILTER in the same place.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    :? What in heavens name do you mean??? Or is my english so bad :(

    If you want to populate a variable you use
    Var := "No."
    

    And there is no use filtering on variables because (unless it is an array) it only contains one value.

    But you can do
    Setrange("No.", Var);
    
  • DenSterDenSter Member Posts: 8,307
    You cannot set filters on variables, you can only set filters on fields in tables. You can use the value of a variable to set the value of the filter:
    MyCodeVariable := '10-001';
    MyCustomer.SETFILTER("No.",'=%1',MyCodeVariable);
    
  • SPost29SPost29 Member Posts: 148
    It looks like you might be wanting to use a "macro substution" (I think thats what we called it in Foxpro)

    if xyz then
    set var := "no."
    else
    set var := "Alt. No."

    setfilter(var,10-110);

    You can't do this in Navision

    I think the closest thing we have would use RecordRef
  • DenSterDenSter Member Posts: 8,307
    What do you mean you can't do this in Navision....
    IF xyz THEN
      MyRecord.SETFILTER("No.",SomeValue)
    ELSE
      MyRecord.SETFILTER("Another No.",SomeValue);
    
    Just because it has different syntax doesn't mean "you can't do that in Navision". Or am I missing something?
  • SPost29SPost29 Member Posts: 148
    Sorry for the confusion, I was trying to make my example simple and of course you can set filters on different fields using an if statement

    maybe this would be clearer

    a function
    setMyFilter(var)

    inside the function

    setfilter(var,somevalue);

    Mostly I was wondering if what he was looking to do was Macro substitution
    In some languages you can substitute a variable for a field
  • barubaru Member Posts: 27
    sorry, if my question is very hard to understand . because my english is very bad. #-o
    so thank everyone for your help.
  • kinekine Member Posts: 12,562
    Of course, you can, you need to use RecordRef and FieldRef to do that...

    I am not sure, this example is not tested, but you need something like this:
      RecRef.GetTable(YourRec);
      FRef := RecRef.FIELD(YourRec."Field Name");  //get the field into fieldref
    
      FRef.SETFILTER(SomeValue);  //set the filter to the selected field
    
      RecRef.SetTable(YourRec);  //set all fitlers back to your record variable
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • barubaru Member Posts: 27
    THX, Kine .
    u re great..
    =D> it's solve my problem :D
Sign In or Register to comment.