text to option string

madmmadm Member Posts: 92
edited 2006-03-23 in Navision Attain
we have a code unit for importing text files to create sales orders.

for a short term measure, when we import, we need to use one of the data fields to trigger an option field..

the option field defaults to "No", and during the import the following is needed :

if data[x] = ABC then

option field := yes

however, this leads, understandbly to the can not convert from text to option..

from reading about this, i "guess" that i need to use optionfield::yes , but im not sure of how to go about this! (and i thought this would be an easy one!!)

Comments

  • HalMdyHalMdy Member Posts: 429
    Yes, you have to use :

    OptionField := OtionField::yes ;

    Please not that if your option is simply Yes/No, it is more easy to use a boolean field. In this case, you can write :

    BooleanField := (data[x] = ABC);

    or :

    if data[x] = ABC then BooleanField := TRUE;
  • krikikriki Member, Moderator Posts: 9,112
    HalMdy wrote:
    if data[x] = ABC then BooleanField := TRUE;
    or better:
    BooleanField := (data[x] = ABC);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • madmmadm Member Posts: 92
    Thanks for your replies. There are other options "available", hence the option field! :D


    I have tried the suggestion (in the create header of the c.u)

    as follows :


    IF Data[20] = ABC THEN
    SalesHdr."Field X" := SalesHdr."Field X"::Yes;


    Although i dont get a compling error, when importing the text file Field X doesnt get populated with Yes :(
  • krikikriki Member, Moderator Posts: 9,112
    madm wrote:
    Thanks for your replies. There are other options "available", hence the option field! :D


    I have tried the suggestion (in the create header of the c.u)

    as follows :


    IF Data[20] = ABC THEN
    SalesHdr."Field X" := SalesHdr."Field X"::Yes;


    Although i dont get a compling error, when importing the text file Field X doesnt get populated with Yes :(
    -Are you sure Data[20] = ABC when importing?
    -Are you sure "SalesHdr" is the record you are saving
    -Are you sure you put the code in the "OnAfterImportRecord"-trigger?
    -extra : don't forget to do a clear of all variables in the fieldlist in the "OnBeforeImportRecord". If in a record a value is blank, it takes the previous value.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • madmmadm Member Posts: 92
    kriki wrote:
    madm wrote:
    Thanks for your replies. There are other options "available", hence the option field! :D


    I have tried the suggestion (in the create header of the c.u)

    as follows :


    IF Data[20] = ABC THEN
    SalesHdr."Field X" := SalesHdr."Field X"::Yes;


    Although i dont get a compling error, when importing the text file Field X doesnt get populated with Yes :(
    -Are you sure Data[20] = ABC when importing?
    -Are you sure "SalesHdr" is the record you are saving
    -Are you sure you put the code in the "OnAfterImportRecord"-trigger?
    -extra : don't forget to do a clear of all variables in the fieldlist in the "OnBeforeImportRecord". If in a record a value is blank, it takes the previous value.


    The import is done via a code unit previously written by a NSC. It does not contain the onAfterImportRecord sections.. Instead amongst others it contains a create header section : relating to the sales order header.

    i have put the code in this create header section (which is where i can see other fields being populated), and within the section there is a clear saleshdr.

    one further point which may help, is that data20 is actually being copied from data6, as this data6 may be set to blank depending on another circumstance. therefore data 20 always contains the original data.

    however, the field populated by data20 shows the correct ABC etc, so this indicates that this process is working..
  • krikikriki Member, Moderator Posts: 9,112
    Try this:
    IF DELCHR(Data[20],'<>') = ABC THEN
      SalesHdr."Field X" := SalesHdr."Field X"::Yes;
    
    The DELCHR with '<>' deletes blanks, CR,LF at the beginning and the end of the string.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.