SOLVED

How can I send 1 email with dynamic content blocks for products they have and products they don't have?

Go to solution
Highlighted
Level 4

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

Just following up with this in the event you missed it. Though enjoying Thanksgiving time off is more likely and well deserved. I have edited and used the Syntax Highlighter in my previous comment with the entirety of the VTL for your review.

Thank you kindly and I hope you and yours have/had a very Happy Thanksgiving weekend!!

Highlighted
Level 10 - Community Moderator

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

If that's your full code, it's missing the common snippet from the top of my Day/Time blog post. (For example, it refers to the variable $ISO8601 which doesn't exist without that snippet included.)

It's also confusing $lead.DMSSubscribed and $lead.DMSSubscribedDate (and all the other pairs of values). The first is a Boolean ("1" or "" in Velocity). The second is your stringified DateTime, which is the one you need to convert to a Date in Velocity.

Highlighted
Level 4

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

That was the full code - but now I have added those 7 lines of code at the top as well as "Los_Angeles" rather than "New_York" - which I assume is fine.

It's also confusing $lead.DMSSubscribed and $lead.DMSSubscribedDate (and all the other pairs of values). The first is a Boolean ("1" or "" in Velocity). The second is your stringified DateTime, which is the one you need to convert to a Date in Velocity.

If your confused by what I've done just imagine how exponentially more lost I am. And remember, this whole time I felt confident I was doing exactly what you had been advising. Clearly not the case. I feel like I'm stuck in a riddle.

I can read your diagnosis - and on a macro level understand the root of the problem - but I'm unclear of the remedy as there appears to be numerous implications and paths from one to several changes required or any combination thereof.

I'll be succinct and methodical for clarity (mine, not yours 😞

- I should only use $lead.DMSSubscribed or $lead.DMSSubscribedDate and not both, right?

- Do I simply just replace all $lead.DMSSubscribed with $lead.DMSSubscribedDate in the code?

- Do I uncheck the $lead.DMSSubscribed box in the Script Token?

Highlighted
Level 10 - Community Moderator

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

- I should only use $lead.DMSSubscribed or $lead.DMSSubscribedDate and not both, right?

Only the DateTime field.

- Do I simply just replace all $lead.DMSSubscribed with $lead.DMSSubscribedDate in the code?

Yes, that is, if you're going to convert a stringified DateTime (i.e., ISO8601 format) field into a Date, that's where you use the DateTime.

However I don't think these are ISO8601 "yyyy-MM-dd'T'HH:mm:ss".  They're actually ISO8601 "yyyy-MM-dd HH:mm:ss". That is, they have a space instead of the letter "T". So you can add this line to the code at the top:

#set( $ISO8601WithSpace = "yyyy-MM-dd HH:mm:ss" )

Then use $ISO8601WithSpace where you're using $ISO8601 now.

Parsing a String to a Date requires that you tell Velocity (actually Java) all the parts of the format.

- Do I uncheck the $lead.DMSSubscribed box in the Script Token?

For clarity, yes, but it's harmless to leave it checked as you won't be using it. Leaving it unchecked means it will always have the value null. That may be more or less confusing if you accidentally use it, I don't know.

View solution in original post

Highlighted
Level 4

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

Yes, that is, if you're going to convert a stringified DateTime (i.e., ISO8601 format) field into a Date, that's where you use the DateTime.

I need to clarify. I actually meant - Do I simply just replace all $lead.DMSSubscribed with $lead.DMSSubscribedDateTime in the code? - NOT $lead.DMSSubscribedDate .

Because the only field I will be using is the 'Product X DateTime' custom fields I converted the datatype from 'Date' to 'DateTime' on (i.e $lead.DMSSubscribedDateTime).

Does that change anything from your previous reply?

I also have a feeling all locations in the code below that says 'date' needs to change in some way as well as possibly deleting line 7 entirely. What do you see that is broken and needs to be changed?

#set( $ISO8601WithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Los_Angeles") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
${display.list( $lead.entrySet(), "\u000a" )}
#if( !$lead.DMSSubscribedDateTime.isEmpty() )
#set( $calDMSSubscribedDateTime = $convert.toCalendar(
$convert.parseDate(
$lead.DMSSubscribedDateTime,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calDMSSubscribedDateTime).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
Level 10 - Community Moderator

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

You don't change any lines in the common header area. I see that you deleted a line, not sure why... all I said was to add the new line for the new ISO8601 format.

The Velocity property names of the fields did not change when you changed the datatype; if you were to arbitrarily change the names in the code you'd just be pointing to null properties. You want to reference the current DateTime fields by their Velocity property names. Those are the names you see when you check the box in the tree and dump the entry set.

Highlighted
Level 4

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

Understood. You're right. I was thinking adding the "good" line and removing the "bad" line made sense BUT I should not be "thinking" as it is too dangerous. It is back to exactly as is with the new line added.

The Velocity property names of the fields did not change when you changed the datatype; if you were to arbitrarily change the names in the code you'd just be pointing to null properties. You want to reference the current DateTime fields by their Velocity property names. Those are the names you see when you check the box in the tree and dump the entry set.

After changing the datatypes I did, in fact, go back and rename the fields properly and therefore the proper Velocity names (Ex, DMS Subscribed DateTime) is reflected in the checkbox tree.

I have corrected the common header area, replaced all $ISO8601 with $ISO8601WithSpace and all $lead.DMSSubscribed with $lead.DMSSubscribedDateTime.

I have tested but it still reflects the same result - as I'm sure you're well aware it would.

Next steps?

#set( $ISO8601WithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Los_Angeles") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
${display.list( $lead.entrySet(), "\u000a" )}
#if( !$lead.DMSSubscribedDateTime.isEmpty() )
#set( $calDMSSubscribedDateTime = $convert.toCalendar(
$convert.parseDate(
$lead.DMSSubscribedDateTime,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calDMSSubscribedDateTime).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end

Thank you so much. I cannot stress enough how grateful I am for your patience and help.

Highlighted
Level 10 - Community Moderator

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

I repeat, can you prove that the property names changed when you changed the friendly field names, or are you guessing?

Highlighted
Level 4

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

I'm sorry. I was wrong. I was not guessing intentionally - I can see the tree identifies the field as DMS Subscribed DateTime, however, rather than copying and pasting, this time I dragged that field into the script editor and it did read as $lead.DMSSubscribedDate.

Highlighted
Level 4

Re: How can I send 1 email with dynamic content blocks for products they have and products they don't have?

Not rushing you, in the event you intended to reply, rather just making it clear I cannot move forward without your help.

Here is my preview-by-list test result...

pastedImage_1.png