Re: Incorrect value displayed in token

Anonymous
Not applicable

Incorrect value displayed in token

Hi all,

I'm attempting to troubleshoot a token that was scripted before I started out. Basically, it's displaying the wrong value, though IT says our CRM is talking to Marketo correctly.

Here is the script I'm working with for the token, checking eligibility for a particular program:

## find closest future appointment

## begin selection logic

#set($matchedAppt = false)

#foreach($appt in ${appointment_cList})

#set($matchedApptDate = false)

#set($currentApptDate = $date.toDate('yyyy-M-d', $appt.appointmentDate))

#set($currentApptOffset = $date.difference($date, $currentApptDate).getMilliseconds())

## if appointment is in future

#if($currentApptOffset > 0 && $appt.orderType == 'LLS')

## first match

#if(! $matchedAppt)

#set($matchedAppt = $appt)

## nth match

#elseif($matchedAppt)

#set($matchedApptDate = $date.toDate('yyyy-M-d', $matchedAppt.appointmentDate))

#end

##endif match

## if comparable

#if($currentApptDate && $matchedApptDate)

#set($difference = $date.difference($currentApptDate, $matchedApptDate).getMilliseconds())

## current closer than existing match

#if($difference > 0)

#set($matchedAppt = $appt)

#end

#end

##endif comparable

#end

##endif future

#end

##endfor

## end selection logic

## begin usage

#if($matchedAppt)

#if($matchedAppt.aWVCheckDeligibility == "Y")

<span>CONFIRMED</span>##

#elseif($matchedAppt.aWVCheckDeligibility == "N")

<span>NOT YET CONFIRMED</span>##

#end

#else

<span>UNKNOWN</span>

#end

When I send myself sample emails, for a lead that should be reading as "CONFIRMED," I'm getting "NOT YET CONFIRMED." I'm guessing there may be an error in the syntax somewhere, but I'm so new to Velocity scripting that I have no idea how to find it. Any thoughts on what might be going on here?

Also, for what it's worth, the fields referenced here are part of a custom object, which I'm not as familiar with. I'm used to doing tokens based on custom fields only. I'm guessing the 'Appt' bit is the object, since that's called "Appointment."

Apologies if I am clear as mud here, and thank you for your help.

4 REPLIES 4
Josh_Hill13
Level 10 - Champion Alumni

Re: Incorrect value displayed in token

Are you sure your test lead or test sample lead is correct for the value you expect?

SanfordWhiteman
Level 10 - Community Moderator

Re: Incorrect value displayed in token

When posting code, please, to save what's left of my eyes, use syntax highlighting (you can use the Java highlighter for Velocity, even though it's not totally accurate).

Anyway, while Josh is abso' right about making sure your testing setup is correct, that code is too convoluted for this task.

If I'm understanding you correctly, you want to get the closest future appointment with full-day granularity. This is a form of the Sorting a target into a list pattern.

## Push axis (current date) onto list

#set( $now = { "appointmentDate" : $date.get('yyyy-M-d') })

#set( $tmp = $appointment_cList.add( $now ) )

## Convert all date-like strings to dates

#foreach ( $appt in $appointment_cList )

  #set( $appt.appointmentDate = $date.toDate('yyyy-M-d', $appt.appointmentDate) )

#end

## Sort entire list by date property

#set( $sortedList = $sorter.sort($appointment_cList,[ "appointmentDate" ]) )

## Is there an object just after the axis object?

#set( $nextPosition = $math.add($sortedList.indexOf($now),1) )

#if( $nextPosition < $sortedList.size() )

  #set( $matchedAppt = $sortedList[$nextPosition] )

#end

Match: $matchedAppt

Anonymous
Not applicable

Re: Incorrect value displayed in token

Hi Sanford!

Sorry for the wall of code, I'll try to highlight in the future.

I'm going to rephrase a bit, as if I can accomplish the following, then I can do better testing to actually understand if the issue is Marketo or our CRM. (Unfortunately our CRM guy is not being responsive to my inquiries...)

Normally, I'd test by pulling the leads onto a smart list by setting the list up as 'if [field] is [not empty] then [add to list]'. Problem is, these fields are part of a custom object, which I don't have as much knowledge about, and from what I can tell, I can't actually use a field from a custom object as a definition for a smart list. Is there any way to get around that? Even being able to pull a list of people who I know for sure have that data would help me answer so many questions...

Thank you again for your help!

-Alex

SanfordWhiteman
Level 10 - Community Moderator

Re: Incorrect value displayed in token

The best UI (if you will) for debugging CRM-synced objects is indeed Velocity itself. For example, by outputting the whole ${appointment_cList} in Draft mode, you can dump the object for each lead in your test list. Arrow through leads at the upper right:

preview-test-lead-list.png