Field Option Value

FishermanFisherman Member Posts: 456
Question about Option Values.

I'm trying to retrieve the selected option value as a text from a table that I've created. I found three methods and functions that I'm trying to put together to do this, but I don't think I've got it right.

I found the SELECTSTR function, which says it allows you to pull an indexed item from a comma separated list. I then found in the description of the Option type that the FieldRef will return a numeric value representing the item in the list that was selected, and then the OPTIONSTRING method, which supposedly returns the option string associated with the field. I tried combining them like so...

textValue := SELECSTR(rec."Option Field",rec."Option Field".OPTIONSTRING)

It's telling me that this is not valid syntax...

Does anyone know how to do this?

Comments

  • krikikriki Member, Moderator Posts: 9,110
    try :
    textValue := FORMAT(rec."Option Field");
    

    An option in reality (=in the DB and also how to use it) is an 0-based-integer. So the first option=0, the second option=1, and so on.
    If you want the string of the option, you have to use it like above.
    If you want to test if an option has a value, or put a value in it, you should do this:
    rec."Option Field" := rec."Option Field"::"Some Option".
    
    It is possible to put rec."Option Field" into an integer-field and an integer field into an option. So if you need to pass an option to a function as a parameter, in the function you can receive it as an integer and then use that integer in the function. An example:
    Function SomeFunction(intDocumentType As Integer)
    BEGIN
      IF LrecSalesHeader."Document Type" = intDocumentType THEN
        ...
    END;
    

    And to call it:
    SomeFunction(recSalesHeader."Document Type")
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • FishermanFisherman Member Posts: 456
    Great Explanation.

    Thanks Kriki!
  • cbmcbm Member Posts: 1
    If you want the numeric value, simply create a variable of type Integer and assign the option field to it like this i := rec."optionField"; You can then use the Format(i) to convert the int to a string

    If your want the option field text represented by the option value use this syntax: FORMAT(rec."yourOptionField");
Sign In or Register to comment.