OptionString instead of OptionCaption in a Report

rwabelrwabel Member Posts: 32
I want to display the value of the OptionString instead of the deafult OptionCaption in a Report. This means I've a field which I use in SourceExpr and it displays on my report the value in OptionCaption, but I would rather have the value from the OptionString. Is there a way to get the OptionString or to indicate which one should be used?

Comments

  • DenSterDenSter Member Posts: 8,304
    I don't think there is anything like that. It is strange though that your option captions are different from the option values. Why would you want to do that? And the next question is then why would you want to display the option value, if anywhere that the user uses that field, they see the caption. WOuldn't that be confusing?
  • rwabelrwabel Member Posts: 32
    the option caption is different because I need in some cases text and in another one a value. For example
    OptionString has the values 2,4,5
    OptionCaption has the values text2,text4,text5
    and then in OptionCaptionML are text2,4,5 in the other languages

    In some forms I need the text, it's more obvious and more readable. In the report I must have the number and not the text.

    Maybe there is another way to solve that problem. I hope I could explain in understandable

    thanks for helping me out :-)
  • DenSterDenSter Member Posts: 8,304
    If you can't get to the values, I'd try writing a little function on the table that returns a string representation of your option field, and put that function as the SourceExpr in your report. It's hard coded, but it does the trick.
  • rwabelrwabel Member Posts: 32
    I'll give that a try, thanks
    If there is another way, I would prefer that one. ;-)
  • rwabelrwabel Member Posts: 32
    I came across this function and I get now all the values from the optionstring:
    http://www.mibuso.com/forum/viewtopic.p ... tionstring

    Is there a way to get the selected value from the OptionString field?
  • ngebhardngebhard Member Posts: 127
    Refering to the topic you posted try the following:

    Create a function called GetOptionValue
    GetOptionValues(Tab : Integer;Field : Integer) : Text[200]
    BEGIN 
      RecRef.OPEN(Tab); 
      FRef := RecRef.FIELD(Field); 
      OptVal := FRef.OPTIONSTRING; 
      RecRef.CLOSE; 
      EXIT(OptVal); 
    END;
    

    Variables in this part are:
    RecRef: RecordRef
    FRef: FieldRef
    OptVal: Text 200

    Then use the following code:
    EVALUATE(OptNo,FORMAT(FieldName,20,'<Number>'));
    
    Val:=GetOptionValues(TableNo,FieldNo);
    
    FOR i:=0 TO OptNo DO BEGIN
      Seperat:=STRPOS(Val,',');
      Result:=COPYSTR(Val,1,Seperat-1);
      Val:=COPYSTR(Val,Seperat+1,200);
    END;
    

    The variables are:
    Val: Text 200
    Result: Text 100
    OptNo: Integer
    i: Integer
    Seperat: Integer

    FieldName is the option field you are using.
    TableNo is the no. of the table, FieldNo the no. of the field.

    As "result" you should receive the value of the option field instead of the caption. This should work! If not: ask again! :-)

    [Edit: the option value is the option string. I mixed the words up. Sorry for that!]

    Greetz
    Nicole
    ProTAKT Projekte & Business Software AG
    Microsoft Dynamics NAV Partner
    Bad Nauheim, Germany
    http://www.protakt.de
    http://twitter.com/protakt
  • krikikriki Member, Moderator Posts: 9,110
    If you gave the first value 0 then 1 then 2, etc... you can also do this:
    intOptionValue := "My Record"."My Option Field";
    
    and print that integer (=intOptionValue).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • rwabelrwabel Member Posts: 32
    @ngebhard: thank you very much for the reply. It's working fine now! I made a 2nd function and put the 2nd code and call now that function directly from the property in the report.
    You are really my hero, I was very astonished that such a function doesn't exist already in navision.

    @kriki: that would be a nice solution, but unfortunately the values aren't like that in my case. thank you anyway
  • rwabelrwabel Member Posts: 32
    I've just noticed that I always get the same value :-)
    I then analysed it with the debugger and found out that
    OptNo is always 0!
    EVALUATE(OptNo,FORMAT(FieldName,20,'<Number>'));
    

    I have a table VarJnlLine and the filed Correction Code with the number 140
    I call the function now:
    ...FORMAT(VarJnlLine."Correction Code",20,'<Number>'));
    
    is that wrong?

    I've also tried with the FILEDNAME function:
    FieldName := VarJnlLine.FIELDNAME("Correction Code");
    
    and then use your function, but then I get an error that an
    incorrect field or attribut was defnied in the Format property.
    <NUMBER> 
    

    Either I've wrongly interprete your code or there must be some kind of a mistake in the code.

    thanks
  • ngebhardngebhard Member Posts: 127
    I became different results when I tried it. Do you wanna send me your report? Just send me an email, I will have a look at it.

    Greetz
    Nicole
    ProTAKT Projekte & Business Software AG
    Microsoft Dynamics NAV Partner
    Bad Nauheim, Germany
    http://www.protakt.de
    http://twitter.com/protakt
  • rwabelrwabel Member Posts: 32
    Should I export it to a txt or fob file? do you need the table too?

    thanks
  • ngebhardngebhard Member Posts: 127
    I think we'vo got it!

    One more thing if someone is interested in:
    if the function gets the last option, there was an error with the COPYSTR caused by the missing comma! I changed the coding:
    FOR i:=0 TO OptNo DO BEGIN
      Seperat:=STRPOS(Val,',');
      IF Seperat<>0 THEN BEGIN
        Result:=COPYSTR(Val,1,Seperat-1);
        Val:=COPYSTR(Val,Seperat+1,200);
      END ELSE
        Result:=Val;
    END;
    

    Now it is supposed to work!
    Greetz
    Nicole
    ProTAKT Projekte & Business Software AG
    Microsoft Dynamics NAV Partner
    Bad Nauheim, Germany
    http://www.protakt.de
    http://twitter.com/protakt
  • BiboBibo Member Posts: 22
    thx, helped me a lot and saved time :wink:
  • jversusjjversusj Member Posts: 489
    great! this helped me as well.

    in our case, we have a need to interface with a 3rd party warehouse management system. we need to send something called an NMFC code to the WMS. In Navision, we want friendly names like Plastic Parts, Cardboard Parts, etc., but we want to send the numeric equivalent to WMS (156600, 152660 respectively in this example). By using this, i can have an option presenting the friendly name in Navision, but send the actual option value to WMS.

    Thanks! \:D/
    kind of fell into this...
Sign In or Register to comment.