SOLVED

Re: Tokenizing Picklists?

Go to solution
Anonymous
Not applicable

Tokenizing Picklists?

Greetings, Marketo Community,

As our office continues to build out our landing pages and forms, we are struggling to keep our product (in this case, degree programs at a university) picklist up to date. Currently, we have over 30 picklist options for programs within our forms.

Is there a way to create a token - universal or at the folder level - that will allow for easy picklist updating when new programs are added, program names are changed, etc?

Thanks in advance,

Matt

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Tokenizing Picklists?

JS if looks like this:

if( condition ) {
  // do something
}

 

Therefore you could use your {{my.token}}, provided the value is allowed within a JS double-quoted string:

if( "{{my.program_language}}" == "English" ) {
  // do something
}

 

However I’d be very unlikely to do it this way. It’s always better to keep JS code out of your LPs and templates.

 

Instead, store the code in a separate .js file you put in Design Studio. Include a different src based on the {{my.token}}, as shown in my earlier post.

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

Re: Tokenizing Picklists?

Matthew Hendrickson​ Great question. FYI. I moved your post to the Products and Support​ where one of our experts is more likely to find it.

Anonymous
Not applicable

Re: Tokenizing Picklists?

Scott - thanks! I'm still fumbling around trying to find the right place for things around here.

-Matt

SanfordWhiteman
Level 10 - Community Moderator

Re: Tokenizing Picklists?

Matthew, are your forms on Marketo-hosted Landing Pages?

Anonymous
Not applicable

Re: Tokenizing Picklists?

Sanford - we use the form fields through Marketo, but place the forms on our institutional pages via iframes.

SanfordWhiteman
Level 10 - Community Moderator

Re: Tokenizing Picklists?

OK, IFRAME is still Marketo-hosted for our purposes.

There are a few different ways to create shareable picklists.  If you want to use a (text) token here's what you can do:

1. Create the token.  It will actually be snippet of simple JavaScript that has all your options in it. Here, I have just copy-and-pasted the code from http://codepen.io/figureone/pen/ZbQbpK.js.  You can use that script as your boilerplate, as it should be easy to see where to plug in the dropdown text and values.  Marketo helpfully removes the carriage returns so it all works on one line.

pastedImage_5.png

2. Add the {{my.picklist}} token to your LP in an HTML element (after adding the Form element).

pastedImage_1.png

3. Profit!

Here it is in action on a Landing Page: Dynamic Picklist​.  You can see that I've added 3 new options to the ones stored in the form descriptor itself. This picklist could also have started from scratch, of course.

Josh_Hill13
Level 10 - Champion Alumni

Re: Tokenizing Picklists?

Sanford, would you want to create that token at a higher folder level and not the Program level? Otherwise you'll have to replicate this multiple times.

SanfordWhiteman
Level 10 - Community Moderator

Re: Tokenizing Picklists?

Yeah, as high as you want!

lianef
Level 1

Re: Tokenizing Picklists?

can you use velocity script tokens to accomplish displaying different language values? I set the program language value using a velocity script token that says #set($ProgramLanguage="french") for example, that token is then referenced in another VS script that looks like this: 

 

#if (${ProgramLanguage}== ("en"))
<script>MktoForms2.onFormRender(function(form) {
var formEl = form.getFormElem()[0],
selectEl = formEl.querySelector("#Dietary_Restrictions__c");

var optionList = [
{
label: "Egg Allergy",
value: "Egg Allergy"
},
{
label: "Fish/Shellfish Allergy",
value: "Fish/Shellfish Allergy"
},
{
label: "Gluten Free",
value: "Gluten Free"
}
];

optionList.forEach(function(optionDesc) {
var newOption = new Option();
newOption.text = optionDesc.label;
newOption.value = optionDesc.value;
selectEl.add(newOption);
});
});</script>
#elseif (${ProgramLanguage}== ("french")) 
<script>MktoForms2.onFormRender(function(form) {
var formEl = form.getFormElem()[0],
selectEl = formEl.querySelector("#Dietary_Restrictions__c");

var optionList = [
{
label: "testingEgg Allergy",
value: "Egg Allergy"
},
{
label: "testingFish/Shellfish Allergy",
value: "Fish/Shellfish Allergy"
},
{
label: "testingGluten Free",
value: "Gluten Free"
}
];

optionList.forEach(function(optionDesc) {
var newOption = new Option();
newOption.text = optionDesc.label;
newOption.value = optionDesc.value;
selectEl.add(newOption);
});
});</script>
#else
<script>MktoForms2.onFormRender(function(form) {
var formEl = form.getFormElem()[0],
selectEl = formEl.querySelector("#Dietary_Restrictions__c");

var optionList = [
{
label: "Egg Allergy",
value: "Egg Allergy"
},
{
label: "Fish/Shellfish Allergy",
value: "Fish/Shellfish Allergy"
},
{
label: "Gluten Free",
value: "Gluten Free"
}
];

optionList.forEach(function(optionDesc) {
var newOption = new Option();
newOption.text = optionDesc.label;
newOption.value = optionDesc.value;
selectEl.add(newOption);
});
});</script>
#end
Darshil_Shah1
Level 10 - Community Advisor

Re: Tokenizing Picklists?

Make sure you highlight your code using the code editor so people here can read it easily. See Jo's blog on how to use the code highlighter while posting codes on the Nation here.

 

Also, to answer your question, you can't use velocity/email script tokens on landing pages. You'd need to use segmentation/Web Personalization/JS for displaying dynamic content on the landing pages. In fact, anything that you do with velocity in emais you can more or less do using the JS on the landing page (as long as you're personalizing content based on Person/Company/Program fields or {{my.tokens}} and not on Custom Objects; COs cannot be accessed on an LP, only in emails via the email script token).