Question about Option fields
                
                    Resender                
                
                    Member Posts: 119                
            
                        
            
                    Ok, I got a question that needs a quick answer.
I got a codeunit to import a csv, I can't use a dataport.
Amongst the fields are 3 option Fields, in the csv i got the values of their OptionStrings,for example Sales Order.
Now I need to put in that into the option field in the table, can I get the value of an Option based on the option string.
                I got a codeunit to import a csv, I can't use a dataport.
Amongst the fields are 3 option Fields, in the csv i got the values of their OptionStrings,for example Sales Order.
Now I need to put in that into the option field in the table, can I get the value of an Option based on the option string.
0                
            Answers
- 
            
 - 
            Considering, Field - "Type" - Option - Contract,Permanent
You can write code similar to the following:
TypeText := FORMAT(Type);
CASE TypeText OF
'Contract':
MESSAGE('Contract');
'Permanent':
MESSAGE('Permanent');
END
Hope this helps.
Chn0 - 
            First thing I would try is to have the integer-values of the options. They are a more secure and language-independent.
(to export an option as an integer: intDocumentType := SalesHeader."Document Type"; export the intDocumentType. It will export an integer and the the caption of the option).
Otherwise you can use EVALUATE. BUT it is language-dependent!Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 - 
            
Yes this is more or less what I want, I was given the assignement to make the code unit to import from a csv file into 2 tables.(As an exta I don't even know how the csv looks)kriki wrote:First thing I would try is to have the integer-values of the options. They are a more secure and language-independent.
(to export an option as an integer: intDocumentType := SalesHeader."Document Type"; export the intDocumentType. It will export an integer and the the caption of the option).
Otherwise you can use EVALUATE. BUT it is language-dependent!
I have very little info further, but I do have the database.
What I want is to get the integer value of the option based on a string.
For instance Sales Retour Order has an integer of 4, Verkoopretourorder is the dutch option for this.
I want to know of there's a way to get the numeric value based on the strings in the optionstrings.0 - 
            Variables:
RecRef: Type - RecordRef
FRef: Type - FieldRef
OptionText: Type - Text250
Code:
RecRef.OPEN(<Your Table Id>);
FRef := RecRef.FIELD(<Your option field id>);
OptionText := FRef.OPTIONSTRING;
I think this may help. Once you get the OptionString from the field and the string data from your file, you can compare the values and see which option it is. Now option values starting from 0, you can easily find out what the integer value will be.
Chn0 - 
            Resender wrote:I want to know of there's a way to get the numeric value based on the strings in the optionstrings.
EVALUATE(SalesHeader."Document Type",txtTheOptionValueAsText);
intDocumentType := SalesHeader."Document Type";Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 - 
            
This works but like you said in a previous post it's not language dependant.kriki wrote:Resender wrote:I want to know of there's a way to get the numeric value based on the strings in the optionstrings.
EVALUATE(SalesHeader."Document Type",txtTheOptionValueAsText);
intDocumentType := SalesHeader."Document Type";0 - 
            Resender wrote:This works but like you said in a previous post it's not language dependant.
That wasn't a requirement in your question..
Look in codeunit 8611,
ValidateOptionValue(VAR FieldRef : FieldRef;OptionValue : Text[250]) Valid : Boolean0 - 
            
Ok had to copy and alter to do thisajhvdb wrote:Resender wrote:This works but like you said in a previous post it's not language dependant.
That wasn't a requirement in your question..
Look in codeunit 8611,
ValidateOptionValue(VAR FieldRef : FieldRef;OptionValue : Text[250]) Valid : Boolean
I added that we should both look in the optionstring as well as the optioncaptionIF OptionValue = '' THEN EXIT; IF EVALUATE(OptionValueAsInteger,OptionValue) THEN BEGIN StartPos := 1; OptionNo := 0; WHILE NOT (StartPos = STRLEN(FieldRef.OPTIONCAPTION) + 1) DO BEGIN IF COPYSTR(FieldRef.OPTIONCAPTION,StartPos,1) = ',' THEN OptionNo := OptionNo + 1; StartPos := StartPos + 1; END; EXIT(NOT(OptionValueAsInteger > OptionNo)); END ELSE BEGIN IF NOT (GetOption(OptionValue,FieldRef.OPTIONCAPTION,OptionValueAsInteger)) THEN BEGIN EXIT(GetOption(OptionValue,FieldRef.OPTIONSTRING,OptionValueAsInteger)) END ELSE BEGIN EXIT(GetOption(OptionValue,FieldRef.OPTIONCAPTION,OptionValueAsInteger)) END; END;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
 - 323 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