Velocity - Format Output from a Text Field Type | Community
Skip to main content
Level 6
July 9, 2021
Solved

Velocity - Format Output from a Text Field Type

  • July 9, 2021
  • 1 reply
  • 2583 views

Hi,

 

we are storing the history of interesting moments in a Text Field, similarly to the approach explained by Dan Stevens here.  We also track the number of those records (interesting moments) in a separate Score field. So, when an interesting moment is created, it gets written in a Text field, each in a separate line, and the Score goes up for 1. To separate entries into different lines, we use this trick by Sanford.

 

Now, we would like to include some of the history of these interesting moments in alerts for our team, but only last 5 entries. As a non-programmer, I checked the documentation for Velocity, and got an idea for the following "pseudo-code" (sorry :):

 

if ScoreField is 5 or less just output the whole content of the Text field else foreach (i in [1..5]) print line #i

 

But I am not so sure this will actually work, especially the counting of lines - because, I think, they are not really an array of values, just text - and its not possible to just iterate over them. Thus I would appreciate if someone can comment if the approach makes sense or not. And if not, any advice on on how to do it would be appreciated!

 

Thanks!

 

;m 

 

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Split, set the max # of lines and then output up to that max:

#set( $lines = $lead.testTextArea01.split("\n") ) #set( $MAX_DISPLAY_LINES = 5 ) #foreach( $lineNum in [1..$math.min($MAX_DISPLAY_LINES, $lines.size())] ) ${lines[$foreach.index]}<br> #end

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
July 9, 2021

Split, set the max # of lines and then output up to that max:

#set( $lines = $lead.testTextArea01.split("\n") ) #set( $MAX_DISPLAY_LINES = 5 ) #foreach( $lineNum in [1..$math.min($MAX_DISPLAY_LINES, $lines.size())] ) ${lines[$foreach.index]}<br> #end
matjazzAuthor
Level 6
July 12, 2021

Thanks, will give it a try!