Hi all,
Hope you are doing well.
I am trying to solve one problem using Velocity to Display " Hi Member" instead of Name in First Name field when it consists of multiple names.
Example : Rodney William Hydes
I was thinking to use length check but we don't know the max chars that can be input in this field. So if it is just one input and length is more than 2 then I have used the code to display the name by taking the index at 0.
However, it seems like I would need another condition when length is greater than 2 and then find a solution to display Hi Member instead of name if its not in one string.
Any inputs will be appreciated. Hope it is not confusing.
Kind Regards,
Vidhi
Solved! Go to Solution.
Why are you referring to character length when what you mean is number of words?
Hi Sanford,
Thank you for your reply.
Yes I meant number of words & in this case, all I am concerned about multiple strings in one field.
Kind Regards,
Vidhi
is there a reason you didn't suggest using .contains(" ")?
I have a vague hunch it is because you're giving the OP a solution that allows them to then use the zeroth element of the array as the name to display, but there are probably many other technical reasons why your approach is better.
Cheers
Jo
No particular reason except that it lets you choose whether to allow 2-part names but not 3-part names.
Nice thinking.
It does also achieve my suggestion - namely giving you an element of the array you can use for the first name if you wanted to not exclude, but actually display something meaningful (and it works for those with only a single first name as well).
Hi @SanfordWhiteman ,
Thank you for your inputs.
I tried that but then I thought I am anyways going to ignore everything & display 'Hi Member' if First Name array will have space even once in name and its not one continuous string with size more than 3. Hence I used the logic as below:
#elseif (${lead.FirstName.length()} <= 2 || ${lead.FirstName.contains(" ")})
Hi Member
#elseif (${lead.FirstName.length()} > 2 )
$display.capitalize(${lead.FirstName})
It is working in my case.
Kind Regards,
Vidhi
OK. You must remove those curly braces as they are not appropriate inside #directives (they break function chaining)
Hi @SanfordWhiteman ,
Thank you for catching it.
Yes, actually I have used a variable to store the value. I just forgot to use it in my code.
Kind Regards,
Vidhi