MyToken issue when one record has multiple Meeting Dates

Chintandoshi25
Level 1

MyToken issue when one record has multiple Meeting Dates

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.

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: MyToken issue when one record has multiple Meeting Dates


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.

Chintandoshi25
Level 1

Re: MyToken issue when one record has multiple Meeting Dates

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
Level 10 - Community Moderator

Re: MyToken issue when one record has multiple Meeting Dates


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.

Chintandoshi25
Level 1

Re: MyToken issue when one record has multiple Meeting Dates

Hey @SanfordWhiteman ,

I am able to fetch the correct meeting value as per the days difference from the multiple Meeting date but I want to change the format of it like Friday, Mar. 05 at 12:00 AM

 

Appointment_Start_DateTime_Text__c is the text data type attribute. The value store in this like : 03/05/2021 10:37:00 AM CST

I don't want to use any static Time zone to convert it because each records have different TimeZone value.

 

So just want to convert the format of date and display in the Email content. Also I want to remove the ss (Seconds) part from the Time.

#set($x = $date.calendar)
#foreach( $Meeting in $Activity_Marketo__cList)
#set ( $Appointment_Start = $date.toDate("MM/dd/yyyy hh:mm:ss a", $Meeting.Appointment_Start_DateTime_Text__c) )
#set($is_upcoming = $date.difference($x.time,$Appointment_Start).days)
#if($is_upcoming == 😎 <br>
$Appointment_Start<br>
#end
#end

 

Using this above script, the Output I received is "Fri Mar 05 10:37:00 CST 2021" but I want it like "Friday, Mar. 05 at 12:00 AM"

Can you please suggest what I need to update in the above script.