We've created a form to use as an RSVP for a Conference inside Marketo. We have built boolean fields that users will check on the landing page depending on which events they want to attend at the conference. The actual field names are shorter than what the user will see and select on the landing page where the form is embedded. The user can choose more than one selection. We would like to send a follow up email after the user has submitted the form with his/her selections. I am trying to figure out how to do the following:
Solved! Go to Solution.
Yep, as predicted by JD, I would do this in Velocity.
## Database field names go on the left, user-friendly names on the right
#set( $booleanFriendlies = {
"Whitebean__c" : "White Bean Hummus",
"Cashew_sicle_1" : "Cashew Creamsicle",
"Pobofu" : "Tofu Po'boy"
})
Your favorite foods are:
#foreach( $fieldin $booleanFriendlies.keySet() )
#if( $lead[$field] == "1" )
$booleanFriendlies[$field]##
#end
#end
This outputs the friendly name for any field that's true.
Yep, as predicted by JD, I would do this in Velocity.
## Database field names go on the left, user-friendly names on the right
#set( $booleanFriendlies = {
"Whitebean__c" : "White Bean Hummus",
"Cashew_sicle_1" : "Cashew Creamsicle",
"Pobofu" : "Tofu Po'boy"
})
Your favorite foods are:
#foreach( $fieldin $booleanFriendlies.keySet() )
#if( $lead[$field] == "1" )
$booleanFriendlies[$field]##
#end
#end
This outputs the friendly name for any field that's true.
Hi Sanford,
After changing the variables in your script to match mine, do I just add this to an email script token in Marketo?
Right. And make sure to check off all the fields you're using in the tree on the right-hand-side of Script Editor.
I checked off the fields. I can't get the information to fill in the body of the email after it is sent to my inbox through a smart campaign. Should I be using the REST API Name or SOAP API Name instead when referencing the fields? Or does the friendly name suffice?
The left-hand-side of the $booleanFriendlies uses the SOAP names. If you are uncertain, you can (temporariily) drag a field from the tree onto the Script Editor "canvas". This will tell you its proper Velocity name.
I still can't get this to show in the body of the email when it is sent to me. I am confident I have the correct token applied in the email. Does anything look wrong with the code?
## Database field names go on the left, user-friendly names on the right
#set( $booleanFriendlies = {
"sessionBooks" : "Books: Thursday, February 1, 11:00 – 11:20am"
})
#foreach( $fieldin $booleanFriendlies.keySet() )
#if( $lead[$field] == "1" )
$booleanFriendlies[$field]##
#end
#end
What do you see if you add this line to the token:
sessionBooks: ${lead.sessionBooks}
(Also pls highlight code using the Advanced Editor's Syntax Highlighter -- v. hard to read otherwise.)
Where exactly do I add that in the token?
Top or bottom, just seeing the raw value of that field.
By adding that line, I get this in the body of the email:
sessionBooks: 1
Looks like you have a typo.
$fieldin
should be
$field in
Hi Sanford,
That did it! Thank you.
One last question in relation to this if that's ok.
The script ultimately has multiple fields that a user can select and be set as booleanfriendlies. When a user selects more than one choice on the form, the script runs, they receive and email, and all of their selections are crammed together. Is there a way to put each selection on a new line when the email is delivered? I am looking at Apache's Velocity docs and having a hard time trying to find it.
Here is what it currently looks like in the body of the email:
Books: Thursday, February 1, 11:00 – 11:20amDocs: Thursday, February 1, 2:00 – 2:20pmSoftware: Friday, February 2, 12:00 – 12:20pm
It should look like this:
Books: Thursday, February 1, 11:00 – 11:20am
Docs: Thursday, February 1, 2:00 – 2:20pm
Software: Friday, February 2, 12:00 – 12:20pm
Sure, add a <br> (and a line break for the text version)
$booleanFriendlies[$field]<br>
Velocity strictly honors all whitespace and strictly prints everything in plain text (unless told otherwise) -- behavior users don't get at first. That means if you have a line break (Unicode 000A), as we do typically hit at the end of lines, that line break ends up in the output, unless we add a ## at the end of the line to comment it out.
Also, Velocity doesn't automatically turn line breaks into HTML <br>, you have to tell it you're in an HTML context (Velocity can be used to pre-process anything, so it's goods that it doesn't force HTML).
It all works now. Thanks for you help Sanford. Do you have any other recommendations besides Apache's documentation for learning Velocity?
get on my bandwagon to get Shea Cibulsky to give Sanford the stage at Summit University Day for a velocity course
Just my posts at
http://blog.teknkl.com/tag/velocity
and, to some degree, the Oracle Java (6) docs.
I don't think there's anybody else writing on these topics, certainly not currently. The Velocity userbase is broad (covering CMS power users and Java developers all over the world) but quite entrenched & quiet. Marketo has likely done more to bring young/new people into Velocity than anyone else, but there are few resources, and even fewer that are accurate. I even had some bugs in some of my earlier blog posts.
The good thing is you can do TONS of sophisticated things with VTL (it's unlimited once you burrow into Java methods) so you won't hit a boundary technically speaking, though you may lose your mind, as I do regularly, figuring out the right patterns.
Hey Ben,
For #2, you can name the fields anything you want in the email body, it's only the token needs to reference the system field name. Another solution to problem #1 is to list all the options in the body of the email with the boolean token for the response next to the values. This will show your default value if empty ("not selected" or whatever you define) or a 1 for True responses, just need to tell the users that 1 = True. See screenshot from Josh Hills MRSG Email preference center. Not as sleek, but it works.
I did something similar, although not with events, using segmentation. If you're looking to combine topics into one sentence, then I'm sure Sanford will have some velocity scripting for you to do. However, all I did was have a trigger watch for the form, then add each user to a segmentation. Then in my email I had as many segmentation fields as I did topics, and the email would only show those that were applicable to that person.
If you can group them that way, it's a pretty easy way to set it up. If this needs to be scalable, then this isn't the answer (you only get a set # of segmentations and you have to set them each up manually).
But -- for those of us not capable of velocity or anything like that, it worked for me.
Note of caution - make sure your email doesn't send immediately and you allow time for your segmentations to update -- test thoroughly.