Assign TXT variable to Option

-matrix--matrix- Member Posts: 103
Hi Everybody!

I'm trying to assign a txt variable to field option but NAV return a sintax error.
I Tried:
Table.Field = Table.Field::TXTvariable;

Do you known the right sintax? Thanks

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Table.Field = FORMAT(Table.Field::TXTvariable);
    
  • -matrix--matrix- Member Posts: 103
    Thanks Mohana! :)
  • -matrix--matrix- Member Posts: 103
    @Mohana I'm Trying but When I execute the code said That TXTVariable Is Invalid Value In the Option field :-k
  • MBergerMBerger Member Posts: 413
    if i read your post correctly, you want to assign the value in a textvariable to an option field ? in that case there is not straghtforward assignment possible, you'll have to use a Case statement or similar construction.

    an example ( using the Status field of T36 Sales Header ) :
    Case Uppercase(TxtVariable) of
      'OPEN' : 
        Salesheader.status := Salesheader.status::open ;
      'RELEASED' :
        Salesheader.status := Salesheader.status::released ;
    End ;
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    You shd try like
    codevar := FORMAT("Replenishment System"::Purchase);
    
  • -matrix--matrix- Member Posts: 103
    Thanks EveryBody.. I Think That I'll use the solution of MBerger :P
  • klavinklavin Member Posts: 117
    MBerger wrote:
    if i read your post correctly, you want to assign the value in a textvariable to an option field ? in that case there is not straghtforward assignment possible, you'll have to use a Case statement or similar construction.

    an example ( using the Status field of T36 Sales Header ) :
    Case Uppercase(TxtVariable) of
      'OPEN' : 
        Salesheader.status := Salesheader.status::open ;
      'RELEASED' :
        Salesheader.status := Salesheader.status::released ;
    End ;
    

    I wouldn't use the CASE for this, you could just use an EVALUATE...
    //Op = ' ,Try,This'    //Option field, the OptionString listed between single quotes.
    //Txt is a text variable
    Txt := 'Try';
    MESSAGE(FORMAT(Op));
    //Message is blank
    EVALUATE(Op,Txt);
    MESSAGE(FORMAT(Op));
    //Message is 'Try'
    Txt := 'THIS';   //Note caps
    EVALUATE(Op,Txt);
    MESSAGE(FORMAT(Op));
    //Message is 'This'
    

    This will cut down on a lot of code for the CASE statements.

    Kevin
    -Lavin
    "Profanity is the one language all programmers know best."
  • kinekine Member Posts: 12,562
    I think that you was not clear in what you want. If you want to assign Text into option, you need to use
      EVALUATE(OptionVar,TextVar);
    

    If you want to assign option value into text than this:
      TextVar := FORMAT(OptionValue);
    

    P.S.:(Klavin was faster... :-))
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • klavinklavin Member Posts: 117
    kine wrote:
    I think that you was not clear in what you want. If you want to assign Text into option, you need to use
    P.S.:(Klavin was faster... :-))

    Woohoo, stole it! :)
    -Lavin
    "Profanity is the one language all programmers know best."
  • MBergerMBerger Member Posts: 413
    klavin wrote:
    MBerger wrote:
    if i read your post correctly, you want to assign the value in a textvariable to an option field ? in that case there is not straghtforward assignment possible, you'll have to use a Case statement or similar construction.

    an example ( using the Status field of T36 Sales Header ) :
    Case Uppercase(TxtVariable) of
      'OPEN' : 
        Salesheader.status := Salesheader.status::open ;
      'RELEASED' :
        Salesheader.status := Salesheader.status::released ;
    End ;
    

    I wouldn't use the CASE for this, you could just use an EVALUATE...
    //Op = ' ,Try,This'    //Option field, the OptionString listed between single quotes.
    //Txt is a text variable
    Txt := 'Try';
    MESSAGE(FORMAT(Op));
    //Message is blank
    EVALUATE(Op,Txt);
    MESSAGE(FORMAT(Op));
    //Message is 'Try'
    Txt := 'THIS';   //Note caps
    EVALUATE(Op,Txt);
    MESSAGE(FORMAT(Op));
    //Message is 'This'
    

    This will cut down on a lot of code for the CASE statements.

    Kevin
    True. Only works in case the text variable uses the exact wording of the option though, which is why i prefer to go for the CASE option in most cases.
  • kinekine Member Posts: 12,562
    Case only works when you have predefined set of values. Why not to use the same set as option values? :-)

    Of corse you can need sometime some mapping. But in most cases it is not from "free text" value...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.