SOLVED

Velocity: Multiple name in First Name

Go to solution
Vidhi_Kare
Level 3

Velocity: Multiple name in First Name

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

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Multiple name in First Name

Just split on space and check the size of the resulting array.

View solution in original post

21 REPLIES 21
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Multiple name in First Name

Why are you referring to character length when what you mean is number of words?

Vidhi_Kare
Level 3

Re: Velocity: Multiple name in First Name

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

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Multiple name in First Name

Just split on space and check the size of the resulting array.
Jo_Pitts1
Level 10 - Community Advisor

Re: Velocity: Multiple name in First Name

@SanfordWhiteman ,

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Multiple name in First Name

No particular reason except that it lets you choose whether to allow 2-part names but not 3-part names.

Jo_Pitts1
Level 10 - Community Advisor

Re: Velocity: Multiple name in First Name

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

Vidhi_Kare
Level 3

Re: Velocity: Multiple name in First Name

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Multiple name in First Name

OK. You must remove those curly braces as they are not appropriate inside #directives (they break function chaining)

Vidhi_Kare
Level 3

Re: Velocity: Multiple name in First Name

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