SOLVED

Re: HELP : Conditional Scripting

Go to solution
nsildeyna
Level 1

HELP : Conditional Scripting

Guys, i need help
#set($testA = "{{lead.change}}") **content is down
#set($testB = "Down")
#if( $testA == $testB )
TRUE OUTPUT
#else
FALSE OUTPUT $testA $testB
#end
when rendered output is FALSE OUTPUT Down Down
Question : why it is not rendering "TRUE OUTPUT" ?? while $testA and $testB is the same "Down"
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: HELP : Conditional Scripting

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.

View solution in original post

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

Re: HELP : Conditional Scripting

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.

Darshil_Shah1_0-1694956553570.png

nsildeyna
Level 1

Re: HELP : Conditional Scripting

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




Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: HELP : Conditional Scripting

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.

nsildeyna
Level 1

Re: HELP : Conditional Scripting

Thanks for responding and bare with me, im pretty new in Marketo 🙂
this is whats available on the right of the template. 

nsildeyna_0-1694975957784.png

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. 

 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: HELP : Conditional Scripting

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?

SanfordWhiteman
Level 10 - Community Moderator

Re: HELP : Conditional Scripting

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

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: HELP : Conditional Scripting

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.

Darshil_Shah1_0-1695009447011.png

nsildeyna
Level 1

Re: HELP : Conditional Scripting

Hi Guys, it is as is from the list on the right.

nsildeyna_0-1695011452635.png

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

 

SanfordWhiteman
Level 10 - Community Moderator

Re: HELP : Conditional Scripting

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.