Is there somthing wrong with EVALUATE...?

voodoovoodoo Member Posts: 82
edited 2005-10-11 in Navision Attain
Hi, I have some problem with this part of my code:
   IF EVALUATE(StatusValue,ValueArray[1]) THEN BEGIN
      SETRANGE(Status,StatusValue);
   END

StatusValue is global variable, type Option;
ValueArray is type of text
Something is wrong with EVALUATE, because if I put only EVALUATE(StatusValue,ValueArray[1]) I have a messagebox:
You cannot enter 'Status::Released' in Option.

:-k

Thnx
misha fka voodoo

Comments

  • kinekine Member Posts: 12,562
    And which value you have in the ValueArray[1]?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • voodoovoodoo Member Posts: 82
    Like I said: Status::Released
    It's the value from the field of my table UserFilter(field type is Text)

    Thnx
    misha fka voodoo
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Have you tried setfilter instead of setrange?

    Setrange expects the same datatype as the field, setfilter accepts strings.

    You might have to remove the Status:: from the string.
  • kinekine Member Posts: 12,562
    You might have to remove the Status:: from the string.

    This is the source of the problems... :-)

    And do not forget, that you will have problems when you switch your language...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,307
    To elaborate...

    You are right in using EVALUATE for this purpose, but you're going about it incorrectly. Syntax like 'Status::Released' is the C/AL code way to designate an option value. Internally, the database stores it as an integer (so you could even just set the filter on the integer value if you know which value that is). The text representation of the option value is just the word that belogns to the option, in your case that would be 'Released'.

    So, try setting your array value to 'Released' and see if that works.
  • voodoovoodoo Member Posts: 82
    Have you tried setfilter instead of setrange?

    Setrange expects the same datatype as the field, setfilter accepts strings.

    You might have to remove the Status:: from the string.
    Problem is EVALUATE not setfilter or setrange, and I tried to remove Status:: from the string and I got the same message. :(
    misha fka voodoo
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    The EVALUATE function is created to do things no other statement can do and basicly acts as if a user enters a field.

    I don't think you have to use the evaluate function in this case. If the string in the user setup table is correct you should only have to make something like

    SETFILTER(Optionfield, UserSetup.Optiontext);

    Just make sure the text value in the usersetup has the right syntax.
  • voodoovoodoo Member Posts: 82
    The EVALUATE function is created to do things no other statement can do and basicly acts as if a user enters a field.

    I don't think you have to use the evaluate function in this case. If the string in the user setup table is correct you should only have to make something like

    SETFILTER(Optionfield, UserSetup.Optiontext);

    Just make sure the text value in the usersetup has the right syntax.

    OK, let me explain, in Sales Header table, Status field is type of Option, and if I want to do this:
    SETFILTER(Status, MyTable.Optiontext);
    I will get an error in compile time: Type conversion is not possible because...
    Option := Text
    and I must do EVALUATE, right!?

    misha
    misha fka voodoo
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Using SETFILTER you can use a string to set the filter, even if the table field has another datatype.

    I think you are getting SETFILTER and SETRANGE mixed up :?

    Have you tried it??

    Make a small test:
    SalesHdr.SETFILTER("Document Type", 'Order');
    form.run(0, SalesHdr);
    
  • voodoovoodoo Member Posts: 82
    edited 2005-10-11
    Mark, thnx it's working :oops:
    But, another problem is when I switch between languages, because, optionstring is text and it's value depend from chosen laguage........example:
    Status::Released (in english) <-> Status::Lansiran (in serbian)
    misha fka voodoo
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, this is the general problem with these type of filtering.

    A workaround can be to work with numbers or to just write some more code.

    You can also replace the text field in the user settings by an option string.

    Do you want to filter on one option only or do you want to set multiple filters like "Quote|Order"??
  • DenSterDenSter Member Posts: 8,307
    Try this:
    SalesHeader.SETFILTER(Status,'=%1',MyTable.Optiontext);
    
  • DenSterDenSter Member Posts: 8,307
    sheesh you guys are posting faster than I can type...
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    That is because we use CodeGenius 8)
  • DenSterDenSter Member Posts: 8,307
    That is advertising, did you pay your sponsorship dues to Luc? [-X
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • DenSterDenSter Member Posts: 8,307
    I won't tell anybody O:)
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • DenSterDenSter Member Posts: 8,307
    I just want to have the last word :-s
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • voodoovoodoo Member Posts: 82
    Yes, this is the general problem with these type of filtering.

    A workaround can be to work with numbers or to just write some more code.

    You can also replace the text field in the user settings by an option string.

    Do you want to filter on one option only or do you want to set multiple filters like "Quote|Order"??

    One option only....
    misha fka voodoo
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    In this case you can also change your text filter in the user setup to an option field, then you won't have problems with the multilanguage thing.

    Sorry for highjacking your topic :oops:
Sign In or Register to comment.