HELP : Conditional Scripting | Community
Skip to main content
New Participant
September 17, 2023
Solved

HELP : Conditional Scripting

  • September 17, 2023
  • 1 reply
  • 3793 views
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"
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman


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.

1 reply

Darshil_Shah1
Community Manager
September 17, 2023

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.

nsildeynaAuthor
New Participant
September 17, 2023

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
Community Manager
September 17, 2023

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.