Options, options

aztecconsultingaztecconsulting Member Posts: 55
Can anyone with expirence with the option datatype give me some help? I have a field "X" setup as an option type with "A" and "B" as the values to choose from. I know I can use IF X::A THEN to catch if the value is "A" but how can I determine if the user hasn't set the option? How can I test for null?

Comments

  • KowaKowa Member Posts: 923
    The empty option is coded as a space.

    IF X = X::" " THEN
    Error('Select an option.')
    Kai Kowalewski
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    If X = X::A then

    else if x = x::b then


    case x of
    x::a:;
    x::B:;
    end;


    If you want a blank; ad an optionstring:

    ,A,B

    Then defualt is

    x::" "

    Greetz,

    Marq
  • DenSterDenSter Member Posts: 8,307
    The space/empty option only works if you actuall enter a space as a character in the option string. Just a comma will not show the option to the user. The string ",A,B" will only show A and B as options. The string " ,A,B" will show A and B as options, but will also allow the user to select blank.
  • aztecconsultingaztecconsulting Member Posts: 55
    IF X = X::" " THEN

    Failed with the error "Option must not be blank. Option missing or invalid in the expression."

    The second reply covers the logic I need to react to "A" or "B" as the answer but that's not what I am looking for.

    What I am looking to test here is to determine if the user hasn't selected any value and the field is essentially null. How can I test for that?
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I Think you should have a look at existing navision functionality, such as table 37 and 81. They use option strings.

    You can always learn from 'standard Navision'. One of the bennefits op 'open source'.

    Greetz,

    Marq
  • DenSterDenSter Member Posts: 8,307
    IF X = X::" " THEN

    Failed with the error "Option must not be blank. Option missing or invalid in the expression."

    The second reply covers the logic I need to react to "A" or "B" as the answer but that's not what I am looking for.

    What I am looking to test here is to determine if the user hasn't selected any value and the field is essentially null. How can I test for that?
    This is because you have to define a space as the blank option, like this "<space>,A,B". If you don't actually enter a space as an option value, Navision is going to yell at you like that.
  • aztecconsultingaztecconsulting Member Posts: 55
    Yeah, I didn't expect that to work. I just can't figure out how to test if the field hasn't been set other than testing every option value in the list. I would rather come up with logic to determine if the field hasn't been set, rather than testing the field against every possible entry in the option list and then reacting to none being true.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    If you now have created a blank option as the first option and you want to check if it is not blank you can enter:
    testfield(Optionfield);
    
    
  • DenSterDenSter Member Posts: 8,307
    The default value of an option type field is always the first selection, unless you specify another one in InitValue. So.... if you add a space as the first option, and you have a business rule that people have to set this, you have a very good way of telling whether the user has 'set' the value, by making sure it is not "blank".

    I believe Mark is right about how to test for this value. If that doesn't help, you can do:
    IF X=X::" " THEN 
      ERROR('slap the user around a bit with a trout');
    
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Or
    ERROR('User error, please replace user');
    
     :D
    
  • jonsan21jonsan21 Member Posts: 118
    IF X = 0 THEN
    Blablablabalbla;

    This will also work....

    Rgds,

    Jon.
    Rgds,

    Jon.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    @ jonsan21

    Yes, this also works, but I don't think I is advisable to learn people on this forum to program like this.

    Some thinks that work are not recomendable for programming.

    Regards,

    Mark
  • DenSterDenSter Member Posts: 8,307
    You are right. When you have an option type field, the values are internally stored as integers. Therefore, you can use the integer values in programming.

    However..... it is a LOT nicer to read if it says X::"My Option Value x", because then you can see right away that 1) the variable/field is an option type field and 2) what the functional value is. With your method, you will have to research the type of the variable/field, and then browse into the property pages to find out what the value represents.

    OR, you have to put a comment behind the value like this
    IF X = 0 THEN BEGIN // this means 'My Option Value 1'
    
    Which, in all fairness, a little silly. If you're going to type the meaning of the integer value in a comment, why not program it that way to start out with.

    An additional advantage is that if you decide to change the option string, it will show the new option value next time you open the C/AL editor.
  • jonsan21jonsan21 Member Posts: 118
    Oh well, I thought some of the standard reports also used this method...

    Anyway, advise taken and noted.

    Rgds,

    Jon.
    Rgds,

    Jon.
  • Jeegen_PrajapatiJeegen_Prajapati Member Posts: 22
    I want when i select value in 1st drop down list than next drop down list in only shows value related to what is selected value in drop down 1.
Sign In or Register to comment.