SOLVED

Re: Question about creation of token

Go to solution
DanielSchneider
Level 1

Question about creation of token

Hello,

I am new in coding tokens in Velocity and have questions about three tokens I created.
I have created the token for a customer and wanted to validate if I used the right conditions in the token.

In this token, marketo checks which product is specified in the field "Intended Use" and which Country is specified.
Here is my question: can I use the & or what I have to use instead?

 

#if($lead.Intended_Use__c.matches("MycoAlert Trial Kit"))&& ($lead.Country.matches("United States"))
C3NA-ER4R-HHJ1
#elseif($lead.Intended_Use__c.matches("MycoAlert Plus Trial Kit"))&& ($lead.Country.matches("United States"))
RGW7-L9MV-X05V
#elseif($lead.Intended_Use__c.matches("MycoAlert Trial Kit"))&& ($lead.Country.matches("Belgium"))
1RAF-E6M2-EDY2
#elseif($lead.Intended_Use__c.matches("MycoAlert Plus Trial Kit"))&& ($lead.Country.matches("Belgium"))
8WUG-W0UA-DTMP
#else

#end

 


The main question for the next token is, if I used the | in the right way as an or condition and if I can use the &.

 

#if($lead.Intended_Use__c.matches("MycoAlert Trial Kit"))&& ("Austria|Belgium|Bulgaria|Croatia|Estonia|Finland|France|Georgia|Germany|Greece|Iceland|Ireland|Latvia|Lithuania|Luxembourg|Malta|Monaco|Netherlands|Norway|Portugal|Romania|Slovenia"))
https://bioscience.lonza.com/Cell-analysis/p/000000000000292126/MycoAlert-Detection-Trial-Kit-%2810-Tests%29
#end
#if($lead.Intended_Use__c.matches("MycoAlert Plus Trial Kit"))&& ($lead.Country.matches("Austria|Belgium|Bulgaria|Croatia|Estonia|Finland|France|Georgia|Germany|Greece|Iceland|Ireland|Latvia|Lithuania|Luxembourg|Malta|Monaco|Netherlands|Norway|Portugal|Romania|Slovenia"))
https://bioscience.lonza.com/Cell-analysis/p/000000000000200686/MycoAlert-PLUS-Detection-Trial-Kit-%2810-Tests%29
#end

 

  
I hope you understand my questions.
If you need more input, just ask.

Thank You.

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Question about creation of token

@SaurabhGoyal_GN there’s a syntax error in your 1st snippet. Please be careful with parentheses. It should be:

 

#if( $lead.Intended_Use__c.equals("MycoAlert Trial Kit") && $lead.Country.equals("United States") )
C3NA-ER4R-HHJ1
#elseif( $lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit") && $lead.Country.equals("United States") )
RGW7-L9MV-X05V
#elseif( $lead.Intended_Use__c.equals("MycoAlert Trial Kit") && $lead.Country.equals("Belgium") )
1RAF-E6M2-EDY2
#elseif( $lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit") && $lead.Country.equals("Belgium") )
8WUG-W0UA-DTMP
#end

 

 

 Also in the 2nd snippet, think you meant to use .equals():

 

#set($countries = ["Austria","Belgium","Bulgaria","Croatia","Estonia","Finland","France","Georgia","Germany","Greece","Iceland","Ireland","Latvia",
"Lithuania","Luxembourg","Malta","Monaco","Netherlands","Norway","Portugal","Romania","Slovenia"])
#if( $lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit") && $countries.contains($lead.Country) )
https://bioscience.lonza.com/Cell-analysis/p/000000000000200686/MycoAlert-PLUS-Detection-Trial-Kit-%2810-Tests%29
#end

 

 

View solution in original post

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

Re: Question about creation of token

In your first code snippet, you're using the && (AND) operator correctly. This means both conditions need to be true for the corresponding code block to execute. For example, if $lead.Intended_Use__c matches "MycoAlert Trial Kit" but $lead.Country doesn't match "United States", so the first #if condition wouldn't be met.

 

You cannot use single & the bitwise AND operator here. It's a more technical operator for manipulating bits within a number and wouldn't achieve the desired logic in this context. Additionally, you should be using the equals() function to match the strings instead of the matches() function, as the latter and the single pipe are used in the context of the regular expression. "|" is used within regular expressions for matching alternative patterns, which I don't think you need here. You should be using logical OR ("||") instead to check whether at least one of the entities separated by the logical OR is true. Alternatively, you can create an array of countries and then reference them directly.

SaurabhGoyal_GN
Level 4

Re: Question about creation of token

@DanielSchneider - you are in almost right direction. Few upgrades - 

1 - Use "equals" function instead of "matches".
2 - Remove "else" from first token in the end of the code.

 

 

#if($lead.Intended_Use__c.equals("MycoAlert Trial Kit"))&& ($lead.Country.equals("United States"))
C3NA-ER4R-HHJ1
#elseif($lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit"))&& ($lead.Country.equals("United States"))
RGW7-L9MV-X05V
#elseif($lead.Intended_Use__c.equals("MycoAlert Trial Kit"))&& ($lead.Country.equals("Belgium"))
1RAF-E6M2-EDY2
#elseif($lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit"))&& ($lead.Country.equals("Belgium"))
8WUG-W0UA-DTMP
#end

 

 

 

For token 2 - You should initialize the array first with the required values and then check if array contains the value of country in that. See below - 

 

 

#set($countries = ["Austria","Belgium","Bulgaria","Croatia","Estonia","Finland","France","Georgia","Germany","Greece","Iceland","Ireland","Latvia",
"Lithuania","Luxembourg","Malta","Monaco","Netherlands","Norway","Portugal","Romania","Slovenia"])
#if($lead.Intended_Use__c.matches("MycoAlert Plus Trial Kit") && $countries.contains($lead.Country))
https://bioscience.lonza.com/Cell-analysis/p/000000000000200686/MycoAlert-PLUS-Detection-Trial-Kit-%2810-Tests%29
#end

 

 


Please have a look and let us know in case you still faces any issues. 

Thanks
 

SanfordWhiteman
Level 10 - Community Moderator

Re: Question about creation of token

@SaurabhGoyal_GN there’s a syntax error in your 1st snippet. Please be careful with parentheses. It should be:

 

#if( $lead.Intended_Use__c.equals("MycoAlert Trial Kit") && $lead.Country.equals("United States") )
C3NA-ER4R-HHJ1
#elseif( $lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit") && $lead.Country.equals("United States") )
RGW7-L9MV-X05V
#elseif( $lead.Intended_Use__c.equals("MycoAlert Trial Kit") && $lead.Country.equals("Belgium") )
1RAF-E6M2-EDY2
#elseif( $lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit") && $lead.Country.equals("Belgium") )
8WUG-W0UA-DTMP
#end

 

 

 Also in the 2nd snippet, think you meant to use .equals():

 

#set($countries = ["Austria","Belgium","Bulgaria","Croatia","Estonia","Finland","France","Georgia","Germany","Greece","Iceland","Ireland","Latvia",
"Lithuania","Luxembourg","Malta","Monaco","Netherlands","Norway","Portugal","Romania","Slovenia"])
#if( $lead.Intended_Use__c.equals("MycoAlert Plus Trial Kit") && $countries.contains($lead.Country) )
https://bioscience.lonza.com/Cell-analysis/p/000000000000200686/MycoAlert-PLUS-Detection-Trial-Kit-%2810-Tests%29
#end

 

 

SaurabhGoyal_GN
Level 4

Re: Question about creation of token

@SanfordWhiteman - Thanks for catching the issue. I read the article as well about this particular you published recently. 

Thanks for the guidance!

Link to the article - https://nation.marketo.com/t5/product-blogs/velocitip-a-syntax-slip-might-not-throw-a-fatal-error-bu...