Using lead tokens in javascript causing errors | Community
Skip to main content
Matt_Stone2
Level 9
October 23, 2014
Solved

Using lead tokens in javascript causing errors

  • October 23, 2014
  • 14 replies
  • 3041 views
I'm trying to set javascript variables using lead tokens, but it looks like the tokens spit out html entity versions (e.g. instead of "Matt" it spits out "Matt"), which cause all sorts of problems with the script.

Has anyone encountered this before?
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 Matt_Stone2
In case anyone finds this thread, I wanted to share the results of my discussion with support:

After being escalated to a higher-tier of support, I was informed that "...engineering was able to respond and let me know that this is unfortunately the intended behavior at this time. The value that is returned is due to us performing an HTML escape on tokens so those are the escape characters (ascii)."

Despite this, you can decode the characters to achieve the desired results with something like this:

var test = "{{lead.First Name}}";  
var decoded = $('<textarea/>').html(test).text();


And then you'll be left with the "decoded" variable that outputs properly.

14 replies

March 30, 2015
Hmm. 

Here is how that renders.

var adroll_custom_data = {
    "curCam": "Mobilizer_SNAP",
 "lastCam": $('<textarea/>').html(&#67;&#111;&#110;&#116;&#101;&#110;&#116;&#45;&#82;&#101;&#99;&#111;&#109;&#109;&#101;&#110;&#100;&#97;&#116;&#105;&#111;&#110;).text(),
 "prd": $('<textarea/>').html().text(),
 "inte": $('<textarea/>').html().text(),

....
}

Still with Escapes.

 
Kenny_Elkington
Adobe Employee
Adobe Employee
March 30, 2015
Whoops, sorry, Adam.  You've got to add quotes those values so JS treats them as strings like:

$('<textarea/>').html("{{my.token}}").text()
March 30, 2015
 "lastCam": $('<textarea/>').html("&#67;&#111;&#110;&#116;&#101;&#110;&#116;&#45;&#82;&#101;&#99;&#111;&#109;&#109;&#101;&#110;&#100;&#97;&#116;&#105;&#111;&#110;").text(),
 "prd": $('<textarea/>').html("").text(),
 "inte": $('<textarea/>').html("").text(),



Cool. No change with quotes. :(
Matt_Stone2
Level 9
March 30, 2015
Did you try decoding them in advance as individual variables like I showed above?