Hello all, not sure if I am crazy or doing something wrong - but running into issues when using a #foreach script with the end result being a URL. Here's my basic test case:
##Standard Velocity Date/Time Fields
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Chicago") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
##iterate Customer Loan object records and set Auto Loan Survey Link Last Updated to usable value for script
#foreach( $item in $customerLoansList )
#set( $autoSurveyURL = $convert.parseDate(
$item.surveyLinkLastUpdatedNewAutoLoan,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
) )
##Sets difference from Last Updated Auto Survey Date and Current Date for between -2 and 0 Days
#set( $pastDiff = -2 )
#set( $currentDiff = 0 )
#set( $diffDays = $date.difference($calNow,$autoSurveyURL).getDays().intValue() )
#set( $acceptableDiffs = [$pastDiff..$currentDiff] )
#if( $acceptableDiffs.contains($diffDays) && ( !$item.surveyLinkNewAutoLoan.isEmpty() ) && (!$item.surveyLinkLastUpdatedNewAutoLoan.isEmpty()) )
<tr id="buttonOnly" mktoname="Button" class="mktoModule">
<td style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0px !important; padding: 0px;">
<!--[if mso | IE]>
<tr>
<td class="" width="600px">
<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600">
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
<tbody>
<tr>
<td style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0px !important; direction: ltr; font-size: 0px; padding: 5px 20px; text-align: center;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="" style="vertical-align: middle;width:560px;">
<![endif]-->
<div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:center;direction:ltr;display:inline-block;vertical-align: middle;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; vertical-align: middle;" width="100%">
<tr>
<td align="center" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0px !important; font-size: 0px; padding: 10px 25px; word-break: break-word;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-collapse: separate; line-height: 100%;">
<tr>
<td align="center" bgcolor="#0071CE" role="presentation" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0px !important; padding: 0px; border: 2px solid #0071CE; border-radius: 6px; cursor: auto; mso-padding-alt: 17px 30px; background: #0071CE;" valign="middle">
<a href="https://$item.surveyLinkNewAutoLoan" style="display: inline-block; background: #0071CE; color: #FFFFFF; font-family: 'Poppins', Arial; font-size: 16px; font-weight: bold; line-height: 120%; margin: 0; text-decoration: none; text-transform: none; padding: 12px 20px; mso-padding-alt: 0px; border-radius: 6px;" target="_blank">Take Survey</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
</td>
</tr>
<![endif]-->
</td> </tr>
#break
#else
#end
#end
When I use preview mode it is pulling the correct URL into the button widget. So it seems like the script itself is somewhat correct. I also followed the recommendations I found to house the entire <a> tag within the script (thus the large button widget formatting).
The issue is on a live test it seems to not resolve through the tracking redirect.
Is there something with Marketo that breaks pulling in a URL from a field? I've done it successfully in other cases but not with the #foreach loop.
Solved! Go to Solution.
Please read my blog post referenced in this thread: https://nation.marketo.com/t5/product-discussions/sorting-output-in-velocity/m-p/334364#M188939
Please read my blog post referenced in this thread: https://nation.marketo.com/t5/product-discussions/sorting-output-in-velocity/m-p/334364#M188939
Got it - makes sense in context. In this case though I'm trying to output the URL from a custom object field so there's potentially x number of records in the object and each URL would be different - well at least a different query at the end.
Technically it should only find one relevant URL per the conditions of the #if statement but like in the blog referenced when resolving it shows the literal variable and not the link itself.
How would it work setting the array like in your example if I don't have a set number of potential records to evaluate and static links to output?
Edit: Would it work to have the static part of the URL be hard-coded and the query string pull from the field?
The link I'm outputting looks like this survey.foresee.com/f/eGEUj2swVY?cpp[email]=heyertommy@gmail.com&cpp[intuvo_id]=394055
So everything after the ? is just a query string and the actual "survey.forsee" URL is always the same.
Secondary Edit: I realized I could remove the tracking code and it should resolve correctly. It'd be great to track it, but it's a relative fix.