SOLVED

How do I make a boolean field show yes or no?

Go to solution
Mollian_Von_Rud
Level 2

How do I make a boolean field show yes or no?

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How do I make a boolean field show yes or no?

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

pastedImage_1.png

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.

pastedImage_2.png

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

pastedImage_6.png

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:

pastedImage_5.png

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.

View solution in original post

17 REPLIES 17
SanfordWhiteman
Level 10 - Community Moderator

Re: How do I make a boolean field show yes or no?

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

Mollian_Von_Rud
Level 2

Re: How do I make a boolean field show yes or no?

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?

SanfordWhiteman
Level 10 - Community Moderator

Re: How do I make a boolean field show yes or no?

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

pastedImage_1.png

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.

pastedImage_2.png

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

pastedImage_6.png

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:

pastedImage_5.png

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.

Robin_Magyar1
Level 1

Re: How do I make a boolean field show yes or no?

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.

pastedImage_1.png

pastedImage_2.png

SanfordWhiteman
Level 10 - Community Moderator

Re: How do I make a boolean field show yes or no?

Velocity doesn't run on LPs. On LPs, use JavaScript:

document.querySelector(".friendlyBoolean").textContent = "{{Lead.Boolean Field}}" ? "yes" : "no";‍‍‍
Robin_Magyar1
Level 1

Re: How do I make a boolean field show yes or no?

Sanford Whiteman

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:

pastedImage_1.png

Robin_Magyar1
Level 1

Re: How do I make a boolean field show yes or no?

Sanford Whiteman

Nevermind - I was able to accomplish what I needed by creating formula fields.

SanfordWhiteman
Level 10 - Community Moderator

Re: How do I make a boolean field show yes or no?

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.

Robin_Magyar1
Level 1

Re: How do I make a boolean field show yes or no?

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!