Options, options

aztecconsulting
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?
0
Comments
-
The empty option is coded as a space.
IF X = X::" " THEN
Error('Select an option.')Kai Kowalewski0 -
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,
Marq0 -
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.0
-
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?0 -
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,
Marq0 -
aztecconsulting wrote: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?0 -
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.0
-
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);
0 -
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');
0 -
Or
ERROR('User error, please replace user'); :D
0 -
IF X = 0 THEN
Blablablabalbla;
This will also work....
Rgds,
Jon.Rgds,
Jon.0 -
@ 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,
Mark0 -
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 thisIF 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.0 -
Oh well, I thought some of the standard reports also used this method...
Anyway, advise taken and noted.
Rgds,
Jon.Rgds,
Jon.0 -
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions