Tokens using Velocity script

mkmarketo1
Level 2

Tokens using Velocity script

Hello- 

I am trying to create a velocity script. For instance, I want anyone who has a 19 in the year segmentation to set date to 1990. 

 

If Year contains 20 set Date to 2000

If Year contains 19 set Date to 1990

If Year contains 18 set Date to 1980

 

How do I write the script to achieve the above?

 

 

 

6 REPLIES 6
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: If else contains statements in Velocity script

You're missing #end at the end of the #if construct. Additionally, you don't need {} around the variable/field unless you are displaying its value

 

#if ($T._Year__c.contains("20")) 
#set($date = "2000")
#elseif ($T._Year__c.contains("19")) 
#set($date = "1990")
#elseif ($T._Year__c.contains("18")) 
#set($date = "1980")
#end
${date}

 

Edit- As Sandy notes, I have a similar question too - Are you sure about using the contains() function? FYR contains() checks for the presence of the substring in a string, as opposed to other functions like startsWith() that check whether the string starts with the specified sub-string.

 

SanfordWhiteman
Level 10 - Community Moderator

Re: If else contains statements in Velocity script

Darshil, I think there’s more going on than just the syntax.

SanfordWhiteman
Level 10 - Community Moderator

Re: If else contains statements in Velocity script

Please return to your thread and check responses, @mkmarketo1.

SanfordWhiteman
Level 10 - Community Moderator

Re: If else contains statements in Velocity script

  1. You really mean “contains”, not “starts with”?
  2. You really mean “contains 18”, not “starts with ‘198’”
  3. How are you getting the variable $T._Year__c onto the Script Editor canvas? That’s a very strange looking variable, it implies the property _Year__c of an object called $T. Marketo Person fields aren’t named that way.
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: If else contains statements in Velocity script

Great points, Sandy! Re point #3, I too noticed the strange object name (T). I thought the OP just replaced the actual object name and replaced it with "T", but always a great idea to confirm with the OP to be 100% clear.

 

SanfordWhiteman
Level 10 - Community Moderator

Re: If else contains statements in Velocity script


I thought the OP just replaced the actual object name and replaced it with "T", but always a great idea to confirm with the OP to be 100% clear.

Hope not because that’s even more confusing.