#set($testA = "{{lead.change}}") **content is down
#set($testB = "Down")
#if( $testA == $testB )
TRUE OUTPUT
#else
FALSE OUTPUT $testA $testB
#end
Solved! Go to Solution.
That’s not what it should look like. Open a P1 ticket immediately, I wouldn’t trust any instance with this behavior to be using tokens correctly.
In proper operation, Script Editor works like this:
Note I removed the formal notation (curly braces) as that’s how you should start working with variables on the canvas. Formal notation is only necessary for output and otherwise can cause unexpected errors.
For the future, please use the code highlighter to highlight the code in your posts. I edited your post this time. You can't use the token reference to assign values/use its data in the velocity script. You need to reference the fields as per the velocity construct (using the "$" character). Also in general you should use .equals() to check for equality instead of "==" as the former is more robust.
#set($testA = $lead.Change)
#set($testB = "Down")
#if($testA.equals($testB))
True Output
#else
False Output
#end
Also, instead of assigning the value of the change field to the $testA variable first, you can directly use it to check whether it’s equal to the value in the $testB field or not (and even just directly check for equality between the $lead.change field and “Down” value instead of assigning “Down” value to the $testB variable altogether).
#if($lead.Change.equals("Down"))
True Output
#else
False Output
#end
Make sure that you pull the person field used in the velocity editor from the object tree on the right, and the little checkbox marked near the field name is also checked.
Hi @Darshil_Shah1 thanks a lot for the reminder and reference.
tried this as per your direction :
#set($testA = "{{lead.belonging_change}}")
#if($testA.equals("Down"))
OUTPUT A
#else
OUTPUT B $testA
#end
but it still renders
OUTPUT B Down
In my comment above, did you read the part where I mentioned using the velocity reference ($) instead of the token reference while referencing fields? Please drag the field from the object tree (per the last snapshot) into the velocity editor instead of trying to reference it through the lead token format. Also, you don't need quotes ("") while assigning a velocity variable with the value in the field. Please reference the scripts in my previous comment.
Thanks for responding and bare with me, im pretty new in Marketo 🙂
this is whats available on the right of the template.
this is what shows after i dragged it from the right
{{$lead.Belonging Increase}}
and renders as
Down
using $lead.Belonging Increase returns nothing
but again, what confuses me is we already got the Down from that token. but when tried
#set($testA = {{lead.Belonging Increase}})
#if($testA.equals("Down"))
OUTPUT A
#else
OUTPUT B
#end
it renders OUTPUT B
while it should renders OUTPUT A
should we convert it to string first?
Really appreciate your help.
For velocity to be able to parse and assign values you must use the $ reference and and not the token reference bein used elsewhere (e.g., emails, landing pages, etc). Use the below script (of course with the "Belonging Increase" field selected in the object tree on the right of the velocity editor):
#set($testA = $lead.BelongingIncrease)
#if($testA.equals("Down"))
OUTPUT A
#else
OUTPUT B
#end
but again, what confuses me is we already got the Down from that token. but when tried
That seems to be a different field than you have added in the latest comment (belonging_change vs. Belonging Increase). Are you sure you didn't have the person token added to the email that might have displayed the "Down" apart from the velocity token you're working on?
It's impossible for the Velocity name of a field to have spaces.
So you cannot have dragged a field with this name from the tree in Script Editor.
(It also would never have double curly braces around it.)
Good point, Sandy! @nsildeyna, when we say drag, we literally mean it (not just copying its as-is name from the tree), i.e., you should click the field in the object tree, hold, and drag the field into the editor. See the snapshot below for reference.
Hi Guys, it is as is from the list on the right.
this when rendered emits "Down" but the problem it didnt catch on the conditional.
but if you put it manually like so :
#set($testA = "Down"}
#if($testA.equals("Down"))
OUTPUT A
#else
OUTPUT B
#end
It renders OUTPUT B
What you’re describing is still not possible unless there is a gigantic bug in your instance alone, which I doubt.
Dot-properties ($lead.property syntax) cannot have spaces. This will create a fatal error in Velocity.
Please post a screen recording of you dragging the field from the tree to the canvas.