Copystr and strlen functions

owiccrossettowiccrossett Member Posts: 13
edited 2007-08-23 in Navision Attain
Hi,

I am in a report and i am trying to write some code in the "source expression" field. what I am attempting to do is to show the last 4 characters of the given field, however when i have a field that does not have any characters it gives me a "less then 0" error.

This is the function that i have come up with:

COPYSTR(PayCheckBuffer[RightSide]."Payroll Control Name",STRLEN(PayCheckBuffer[RightSide]."Payroll Control Name")-3,4)

so how do i write this script so that it only returns the last four characters if there is a value in the field?

thanks a ton,

chris

Comments

  • SavatageSavatage Member Posts: 7,142
    1)a few questions first is "Payroll Control Name" always the same # of characters Except when it's blank?
    2)Is It normal to be blank?

    3) Make a Variable varPayContolName

    Do something like
    IF (STRLEN("Payroll Account Name") > 3)
    then
    VarPayControlName := varPayControlName:= COPYSTR("Payroll Control Name",((STRLEN("Payroll Control Name"))-3),4)
    Else
    VarPayControlName := 'Oops'; //Whatever you want to do if it's blank

    varPayControlName will then be the sourceExp Field.
  • David_CoxDavid_Cox Member Posts: 509
    Just a little note:

    When you are selection from a point to the end of a string you do not need to specify the length.

    so you can leave out the ,4 and the()
    COPYSTR("Payroll Control Name",STRLEN("Payroll Control Name")-3)

    :)
    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.