MyToken issue when one record has multiple Meeting Dates | Community
Skip to main content
New Participant
February 19, 2021
Question

MyToken issue when one record has multiple Meeting Dates

  • February 19, 2021
  • 1 reply
  • 2182 views

Hello,

#if( !$display.alt($Activity_Marketo__cList.get(0).Appointment_Start_DateTime_Text__c,"").isEmpty() ) #set ( $Appointment_Start = $date.toDate("MM/dd/yyyy hh:mm:ss a", $Activity_Marketo__cList.get(0).Appointment_Start_DateTime_Text__c) ) ${date.format("MM/dd/yyyy", $Appointment_Start)} #end

 

We are adding above velocity script code to retrieve meeting details in the email content. But the emails are fetching the first available meeting date and not fetching the correct meeting date as per the campaign conditions as one record has multiple meetings.
How can I displayed the date as per the Smart campaign's date conditions such as StartDateTime (data type=datetime) in future after 7 days.

The field I am using in the velocity script is Appointment_Start_DateTime_Text__c(Data Type=Text).
Appointment_Start_DateTime_Text__c and StartDateTime both have the same value just the data type is different.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
New Participant
February 19, 2021

But the emails are fetching the first available meeting date and not fetching the correct meeting date as per the campaign conditions as one record has multiple meetings.

It's not so much "but" — your code specifically seeks the first item in the list (list.get[0] →  list[0] → first item). So it's not surprising that that's the one that's used!

 

First, you need to read the seminal post on dates and times in VTL:

 

https://blog.teknkl.com/velocity-days-and-weeks/

 

Make sure you read the guidance thoroughly as it's critical to getting correct output.

 

Then you would approach the code like this:

  • sort the list, ascending, by your datetime field
  • loop over the sorted list
  • convert the datetime field to a real Calendar object $calAppt (using $convert.toCalendar & $convert.toDate)
  • use $date.difference($calNow,$calAppt).getDays() to determine how many days from now the current appointment is
  • #break out of the loop when you find the first value that's 7 days in the future

 

Note even though you said the field has DateTime and Text variants, they both are Strings when they first enter Velocity and must be created to true Dates/Calendars. You can't do Date math with Strings.

New Participant
February 22, 2021

Hey @sanfordwhiteman,

 

I wasn't able to understand how we can take care of the scenario using the solution you shared. Can you please elaborate here. As I believe sorting it date wise won't still provide us to final solution.

SanfordWhiteman
New Participant
February 22, 2021

Can you please elaborate here. As I believe sorting it date wise won't still provide us to final solution.

Sorting is only one part of the steps I outlined above!

 

Sorting a list in advance is how you ensure that once you find the first matching item, you can #break. Sorting doesn't do any matching in itself. It prepares the list for easier processing.*

 

What are you looking for elaboration on? If you implement what I've described, you'll see it meets the requirements.

 

 

 

 


*Yes — for any far-future dev coming upon this post —

traversing the list only once to find matches has O(n) complexity,

after which you could sort only the matches for probably lower overall complexity.

However, even though sorting in advance adds implicit overhead, for the list sizes we

deal with in the Marketo Velocity context it makes no difference, and makes for easier-to-read code.