I have a very simple template
<!doctype html>
<html>
<body>
<div class="mktEditable" id="mainContent" mktoname="Main Content">
{{my.scriptTokenContent}}
</div>
</body>
</html>
With the content of my script token being the following
<p>programId:$programId</p>
#foreach($item in $scriptTokenContent_cList)
<p>CampaignId:$item.campaignId,<br/>class $item.campaignId.class</p>
<p>inside for each => programId:$programId,<br/>class: $programId.class</p>
#set($campaignIdInt = $convert.toInteger($item.campaignId))
#set($programIdInt = $convert.toInteger($programId))
#set($campaignId = $item.campaignId)
#set($isCampaign = $campaignIdInt.equals($programIdInt))
#set($isCampaignString = $campaignId.equals($programId))
<p>isCampaign: $isCampaign</p>
<p>isCampaignString: $isCampaignString</p>
#if( $isCampaign || $isCampaignString)
<p>This is the campaign content from the custom object: $item.content0</p>
#else
<p>$campaignIdInt is not equal to $programIdInt or $programId</p>
#end
#end
The intent is to use content from custom objects that are linked to the lead based on the program.
I have followed the guide here on how to access the program ID in the velocity script.
When I preview this email as a user that has the custom object I get the following output
programId:1062
CampaignId:1062,
class class java.lang.String
inside for each => programId:1062,
class: class java.lang.String
isCampaign: false
isCampaignString: false
1062 is not equal to $programIdInt or 1062
Neither comparing the two strings that are both "1062" nor converting them to integers to compare works.
What am I missing here, thanks in advance.
You’ve done a good job describing the issue and your tests.
But you can’t be using the exact code from my blog post because that code doesn’t set $programId. It sets $MAContext.programId, i.e. a property on an object. What is the actual code you’re using to export the Program ID?
Hi @SanfordWhiteman - nice to meet such a renowned Marketo expert! I edited the example from your blog post so that it reads
#set($programId = "{{Program.Id}}")
<p> The rest of the unsubscribe html with links et al</p>I didn't need the campaignId so I simplified it a little, should this change matter?
I didn't need the campaignId so I simplified it a little, should this change matter?
It doesn’t matter in this specific case, but there’s no way of knowing how $programId is set if you don’t show the code!
Anyway, after a couple hours of debugging, I found no way to use the $programId when it’s in that different Velocity context — putting stuff in the Unsubscribe HTML is meant for outputting the values, not using them in additional logic. It doesn’t have to do with String vs. Integer, it’s a cross-context/cross-scope question. (Technically, I was able to get the entry where $scriptTokenContent.campaignIdequals $programId and print its content0, but if there’s no matching entry in $scriptTokenContent_cList it will print ugly output and there’s no way to set a fallback.)
Suggest you switch to the “defineburger” technique to get {{program.Id}} instead of using the Unsubscribe HTML — search earlier posts for details.
I'll have a look for the `defineburger` approach, thanks.
You mind sharing how you were able "to get the entry where $scriptTokenContent.campaignId equals $programId and print its content0" - the process I've set up guarantees that each lead in the program list will have the expected content0 in the custom object.
In Velocity, $programId is not a plain string or integer. It’s a Marketo token value that gets resolved late and behaves more like a wrapped object. When you print it, Velocity renders 1062, but when you try to compare it using .equals () or after converting it, the comparison fails because the underlying object types are still different. That’s why:
String comparison fails even though both look like "1062"
Integer comparison fails even after toInteger ()
This is expected behavior in Marketo Velocity and not a bug in your logic.
Use concatenation to coerce the values into plain strings before comparison.
#set($campaignIdStr = "" + $item.campaignId)
#set($programIdStr = "" + $programId)
#if($campaignIdStr == $programIdStr)
This might works because you are comparing two actual strings, not token-backed objects.
Thanks for the suggestion @Sant_Singh_Rath, I've tried that but coercing to a string like you suggest didn't work.
Do you know if its possible to set a mktoNumber variable in the meta and then access that in the script token?
Thanks for the suggestion @Sant_Singh_Rath, I've tried that but coercing to a string like you suggest didn't work.
There’s no need to convert a java.lang.String to a string — that just creates another string! And concatenating with "" is the same as calling toString() on an object that implements a stringifier; you should call toString() instead of relying on this “syntactic sugar.”
In Velocity, $programId is not a plain string or integer. It’s a Marketo token value that gets resolved late and behaves more like a wrapped object. When you print it, Velocity renders 1062, but when you try to compare it using .equals () or after converting it, the comparison fails because the underlying object types are still different. Th
I have no idea where this content is coming from but it seems irrelevant to Marketo. For one thing, $programId isn’t a Marketo system field at all, and it is a java.lang.String. Was this content created by AI?
No, it comes from an edit to the solution in your blogpost - see response here
No, it comes from an edit to the solution in your blogpost - see response here
(I was asking where Sant’s advice came from because it wasn’t pertinent to the situation.)