Filter a option field

LeroyLeroy Member Posts: 199
Dear folks, I think this is easy. I'd like to know the condition to get the different result of a field type option. I mean, I want a similar code like this:

IF customer.Blocked=customer.Blocked<>" " THEN block:=text1;

I want that filter all the registers different from empty.
Thanks for help

Comments

  • bbrownbbrown Member Posts: 3,268
    IF Blank is the first value in the list:

    IF customer.Blocked > 0 THEN block:=text1;

    However the statement (block:=text1) may not work. An option field is stored as an integer. It need to be either assigned as an integer (block := 1) or by it's option list (block := block::"option 1").
    There are no bugs - only undocumented features.
  • MAJB1969MAJB1969 Member Posts: 44
    The option field can be referenced by name or by number from 0 to n. Blank is usually referenced as 0.

    Try this code below


    IF Customer.Blocked <>0
    THEN block := text1;

    Regards

    MAJB
  • LeroyLeroy Member Posts: 199
    Perfect!!!, Thank you very much for help.
    =D>
  • LeroyLeroy Member Posts: 199
    Sorry, only one question; if I want to show a text if a condition is true, I mean; If blocked is <> 0 then blocked:='Customer blocked". How can I do that if blocked is a option field and the text is text?.
    Thanks again.
  • bbrownbbrown Member Posts: 3,268
    Textvar := FORMAT(Customer.Blocked );

    Using FORMAT will dispaly the option string value instead of the integer.
    There are no bugs - only undocumented features.
  • kinekine Member Posts: 12,562
    I think that there is good place to mention some rules for using option data type:

    1) When possible and you need to use specific option value, use the operator :: - it means something like myOptionVar::"Option 1". You can write it as myOptionVar::"1" and after reopening the object NAV will automatically "expand" the number by correct value.
    -easy
    -readable

    2) When you need to pass some option into some function, you can use integer variable, but use it only with caution and in cases, when you are working only with the variable, not with some specific values (you do not need use "constants" in the code).

    3) Never use integer constants instead option constant in the code. Nobody else will know what does it mean. It is not possible to maintain that (e.g. in case when bad things happen like when you need to insert new option into existing one - but this is example of really bad thing).

    4) Never, NEVER, use text constant in connection with option value (like myOptionVar := 'Option 1'). This will not work in another language than you wrote it, it will not work when somebody change the caption on the option, simply - It will not work... (with exceptions)

    5) You can think about Option as about integer, but only for math operations with the options like comparison, adding, subtracting. But when comparing, use point 1 to compare with specific value...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bbrownbbrown Member Posts: 3,268
    One other tip:

    When adding custom option values, to a standard option field, add a few blank option values after the standard NAV values and before yours. For example, if the base NAV option string is [NAVoption1,NAVoption2,NAVoption3], then make the string [NAVoption1,NAVoption2,NAVoption3,,,,YourNewOption] instead of [NAVoption1,NAVoption2,NAVoption3,YourNewOption]. This way is NAV adds a new option or two, it won't conflict with data from your custom value.
    There are no bugs - only undocumented features.
  • kinekine Member Posts: 12,562
    Of course, this is example how to precede the possible problems...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LeroyLeroy Member Posts: 199
    Good advices;Thanks both for help.
Sign In or Register to comment.