How to copy field to another

nikeman77nikeman77 Member Posts: 517
hi all,

I have a field as follows:

FieldNAME: Source | Modified By | Modified Date
DataType: (Code50) | (Code(20) | DateTime
Sample1 : dynmicsusr21 19/01/12 09.01 33PM | |
Sample2: dynmicsusr2119/01/12 05:02 55AM | |

Expected dynmicsusr21 19/01/12 09.01 33PM | dynmicsusr21 | 19/01/12 09.01 33PM
result dynmicsusr2119/01/12 05:02 55AM | dynmicsusr21 | 19/01/12 05:02 55AM

How to achieve it ? Note that Sample1 is with space between UserID and DateTime, Sample2 is with NO space.

The good news is that ALL UserID is the same (in this case we use dynamicsusr21).

Answers

  • David_CoxDavid_Cox Member Posts: 509
    Not sure what you want here?
    "Modified By" := USERID; 
    "Modified Date" := CURRENTDATETIME;
    Source := STRSUBSTNO('%1 %2', "Modified By","Modified Date");
    

    "Modified By" = DYNMICSUSR21
    "Modified Date" = 19/01/12 09.01 33PM
    Source = DYNMICSUSR21 19/01/12 09.01 33PM

    HTH

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • nikeman77nikeman77 Member Posts: 517
    hi david,

    The original data (userid + CurrentDateTime) was in source field, i would like to copy them to modified by & modified date respectively.
  • David_CoxDavid_Cox Member Posts: 509
    This should work for both examples, put it in a function add some tests and error messages if required

    Variables:
    TempSource - Code - 50
    ToDate - Date
    ToTime - Time
    //EVALUATE(Source,'dynmicsusr21 19/01/12 0901 33PM');
    
    //Normalize the data remove the spaces, periods and colons in variable TempSource
    TempSource := DELCHR(Source); //This removes all spaces
    TempSource := DELCHR(TempSource,'=','.:'); //This removes : and .
    
    //28 Character variable left DYNMICSUSR2119/01/12090133PM
    //First 12 Characters are the USERID
    "Modified By" := COPYSTR(TempSource,1,12);
    
    //Trim the variable
    TempSource := COPYSTR(TempSource,13);
    
    //Extract the date to a variable
    EVALUATE(ToDate,COPYSTR(TempSource,1,8));
    
    //Trim the variable
    TempSource := COPYSTR(TempSource,9);
    
    //Evaluate the time 090133PM becomes 21:01:33
    EVALUATE(ToTime,TempSource);
    
    //User the Variables to create the Date Time Stamp
    "Modified Date" := CREATEDATETIME(ToDate,ToTime);
    
    //MESSAGE('%1 %2',"Modified By","Modified Date");
    

    Stripped down Version
    TempSource := DELCHR(Source);
    TempSource := DELCHR(TempSource,'=','.:');
    "Modified By" := COPYSTR(TempSource,1,12);
    EVALUATE(ToDate,COPYSTR(TempSource,13,8));
    EVALUATE(ToTime,COPYSTR(TempSource,21));
    "Modified Date" := CREATEDATETIME(ToDate,ToTime);
    

    HTH

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
Sign In or Register to comment.