Announcement

Collapse
No announcement yet.

Shorten (Truncate) Text Field?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shorten (Truncate) Text Field?

    If you wish to truncate a text field you can use this little script I found on the internet (My thanks to the original Poster... whoever he was!)...

    Problem: You have a several dozen large pieces of text in the form of a Notes.
    You wish to display them in an Editable Grid but the notes are to large and cumbersome to be viewed in this manner.
    Solution: In the editable grid, truncate the text displayed - you'll only see the full text if you Edit or View the Note Details.

    Script: onLoadRecord Event

    $string = {Note}; // Name of the Field
    $len = 150; // Length of Truncated Text

    if (strlen($string) > $len) {

    // cut string to 150 characters
    $string = trim(substr($string, 0, $len));

    // make sure last word is split at a space and add ' ...'
    $string = substr($string, 0, strrpos($string, " "))."…";

    } else {
    // if string less than 150 Characters add ' ...' to end
    $string .= "…";
    }
    // Set Note Field equal to truncated string
    {Note} = $string;
    Last edited by primitive_man; 01-16-2014, 09:41 PM. Reason: SOLVED
Working...
X