I'm currently trying to use a boolean field to add a check box to my form. How do I make the field come over as true/false or yes/no? Currently it's just showing a "1" if the box is checked and that is it.
Solved! Go to Solution.
Add a new Email Script token at the highest folder level of Marketing Activities (Velocity is the language used to author Email Script tokens, so I call them "Velocity tokens" becase it's more direct and Velocity is not just used in Marketo).
You can give the {{my.token}} the same name as the corresponding {{lead.token}} because they refer to the same underlying field. In this case I'm using the field called Breakfast Invitation.
In Script Editor, make sure to check off the field you're going use in the tree on the right-hand-side and temporarily drag the field onto the Script Editor "canvas" to find out its Velocity name (VTL names are not always the same as the original field name, for example they cannot have spaces so Marketo makes sure they have a valid name).
Copy out the name of the field, in this case Breakfast_Invitation__c. Then delete everything from the canvas. Don't uncheck the field though.
Replace the placeholder your_field_name in this simple code with the Velocity name of the field:
#if( $lead.your_field_name.equals("1") )
yes##
#else
no##
#end
Then paste the code into Script Editor. In this screenshot I've replaced in the name of the field copied out earlier:
Now you're done. Include {{my.Breakfast Invitation}} where you would have used {{lead.Breakfast Invitation}} and you'll get "yes" or "no".
Follow the same pattern with any other Boolean field. You can also write a macro for this, but I didn't want to delve to deep in this thread.
Yes, for an output email. We have an alert email that will be sent once the form is filled out with all the field values. How do you go about using a velocity script token?
Add a new Email Script token at the highest folder level of Marketing Activities (Velocity is the language used to author Email Script tokens, so I call them "Velocity tokens" becase it's more direct and Velocity is not just used in Marketo).
You can give the {{my.token}} the same name as the corresponding {{lead.token}} because they refer to the same underlying field. In this case I'm using the field called Breakfast Invitation.
In Script Editor, make sure to check off the field you're going use in the tree on the right-hand-side and temporarily drag the field onto the Script Editor "canvas" to find out its Velocity name (VTL names are not always the same as the original field name, for example they cannot have spaces so Marketo makes sure they have a valid name).
Copy out the name of the field, in this case Breakfast_Invitation__c. Then delete everything from the canvas. Don't uncheck the field though.
Replace the placeholder your_field_name in this simple code with the Velocity name of the field:
#if( $lead.your_field_name.equals("1") )
yes##
#else
no##
#end
Then paste the code into Script Editor. In this screenshot I've replaced in the name of the field copied out earlier:
Now you're done. Include {{my.Breakfast Invitation}} where you would have used {{lead.Breakfast Invitation}} and you'll get "yes" or "no".
Follow the same pattern with any other Boolean field. You can also write a macro for this, but I didn't want to delve to deep in this thread.
Thanks for this, was very helpful!
What's the JS if the field is blank and Id like to keep it blank? As it defaults to NO if no value is found.
Cheers, Ryan
You can use the code with an unlimited number of fields.
The macro I was referring to is this one: https://blog.teknkl.com/streamline-your-code-with-a-display-if-filled-velocimacro/
Hi Sanford Whiteman,
I've implemented this code for use on a subscription confirmation page, with the intention of the page showing Yes or No based on selections made on the subscription page, but the output I'm getting is the {{my.token}} rather than Yes or No.
Here's a screenshot of the email script I added, based on what you instructed above, as well as the confirmation page showing the token. Can you see anything wrong with it?
Is there a minimum amount of time that needs to pass to allow the script to update the value? I know virtually nothing about velocity scrips, so that question may not even be relevant.
Velocity doesn't run on LPs. On LPs, use JavaScript:
document.querySelector(".friendlyBoolean").textContent = "{{Lead.Boolean Field}}" ? "yes" : "no";
Thank you!
Is that the exact text I need to enter in place of {{my.your_field_name}} from my screenshot? I just tried that, and now the page shows this:
No, you need an HTML element (referred to by its class in the code above), then the JS:
<span class="friendlyBoolean"></span>
<script>
document.querySelector(".friendlyBoolean").textContent = "{{Lead.Boolean Field}}" ? "yes" : "no";
</script>
Also, there was a typo in the code originally as I typed it on my phone, pls use the code as edited..
@SanfordWhiteman I am trying to do the same thing and I followed all your instructions to create the token - very easy to follow so thank you. I simply put the token in the sales alert email and did a test. The data is not being passed through the token to the email alert. The field is in a form that is hosted on a WP LP. Maybe I need to do something like this user did and add JS to my WP LP? Or should the token just work as a token?
Thanks!
Brenda
Did you ensure that you checked off the field in the tree in Script Editor? Pls show a screenshot of the Script Editor canvas/tree.
Hi, here is a screenshot of the token in the tokens section and of how i put it in the email alert.
Thanks!
Brenda
That code will output either yes or no in all cases.
Are you testing with a real email (you should) or a sample? Are you certain that the token exists in the right part of the campaign hierarchy relative to the send?
Ok, I moved the token from the highest level at marketing activity (the very first folder) and put it in the actual program. And it worked! Thanks so much! What a relief 🙂
Nevermind - I was able to accomplish what I needed by creating formula fields.
Formula fields aren't right for this, as you would need a formula field to accompany every single Boolean! I provided the code in my response.
I didn't see your response with the JS until after I responded. I've updated it and everything is working well now. I agree the formula fields longer term wouldn't work, way too many new fields would be required. Thanks again for your help!
When you say "show" do you mean "output in an email"?
A Boolean is stored internally as true/false, but has output (stringified) values of "1"/"" unless you use a Velocity script token to change to "yes" or "no".