Here is what I'm being told from above that I need to solve for. I can't figure this out.
Think of our product model as DirecTV. A customer can go online and select (subscribe) to any channel or combination of channels they choose. - - So I have 10 ala carte products and a new subscriber signs up to any 1 single product or any number combination up to all 10 products. I only want ONE email to be sent per new subscriber regardless of how many products they subscribed to at one time. Then I will send a 2nd email later. Is it possible - and practical - to acknowledge each product they subscribed to uniquely with a text block and/or image for each AND a different text block promoting the products they did not subscribe to? And if not, what is the best way to handle this type of situation?
So many questions: 1. Segmentation logic? 2. Snippets, dynamic emails or unique streams or programs? 3. Engagement or Default Programs? 4. How to ensure ONLY 1 email regardless of new subscriptions deploys? 5. Smart campaign total and goal?
Any thoughts and or advice on how to handle this initial entry via new subscribers would be a life saver. Thank you!
Solved! Go to Solution.
- 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.
That worked - and is the below image. Progress!
OK, that means your Smart Campaign wasn't in the right place in the MA hierarchy and didn't have the token available. Make sure the Program w/the SC can see the token (as is the case w/all tokens).
Yes, you can add HTML where you currently have plain text. Velocity just outputs what you tell it to, it doesn't think about whether it has HTML tags or not.
That worked - and is the below image. Progress!
Obviously, it can't display like this. I will play with this and test until I get to the desired result (2nd image below) but please let me know what you see clearly needs to be corrected and/or just any tips.
Ideally, I'd like to have a sentence or two accompanied by an image as seen below for each unit of code (product section) which comes from my original unique emails. Can I just cut and add the HTML to the "You subscribed to DMS within the past 24 hours." section? Which should work but is that the way to do it?
If you say, yes, am I crazy or does this mean this framework is 100% completed and ready to go?
PRODUCT 01 = True
PRODUCT 02 = False
What about when you right-click someone in the Lead Database, choose Marketing » Send Email?
Thank you so much! That helped. So I tested meticulously, unit of code by unit of code, and then collectively a whole and in the preview-by-list mode it reflected all "true's" appropriately as well as all the "false's". That's a huge win as it clearly appears to be working perfectly.
That said, when I run a smart campaign and actually send that same email - it's blank. So not exactly working perfectly. Does this make sense to you and/or what can I do from here?
You don't need to test all the code at once. Isolate a representative unit of code and test only that.
This opening snippet, using the first field, works for me:
#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.dMSSubscribedDate.isEmpty() )
#set( $caldMSSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.dMSSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$caldMSSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
If I set $lead.dMSSubscribedDate to 2019-12-05 03:00:00 (n.b. running this code at 2019-12-05T19:10:06Z, later on the same day) then I get the expected output:
You subscribed to Product X within the past 24 hours.
If I set $lead.dMSSubscribedDate to 2019-12-04 03:00:00 (one day earlier) then I get no output, also as expected.
Sanford Whiteman Can you please help me make this work?
I feel like the code below is precisely what you have advised me to do, however, since tests still display incorrectly as they have before. Obviously, I've done something wrong but I am unable to identify and correct it.
Please and thank you.
#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.dMSSubscribedDate.isEmpty() )
#set( $caldMSSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.dMSSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$caldMSSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.cRMProSubscribedDate.isEmpty() )
#set( $calcRMProSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.cRMProSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calcRMProSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.bHPHSubscribedDate.isEmpty() )
#set( $calbHPHSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.bHPHSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calbHPHSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.autoCheckSubscribedDate.isEmpty() )
#set( $calautoCheckSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.autoCheckSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calautoCheckSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.oAPSubscribedDate.isEmpty() )
#set( $caloAPSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.oAPSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$caloAPSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.dealerWebsitesSubscribedDate.isEmpty() )
#set( $caldealerWebsitesSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.dealerWebsitesSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$caldealerWebsitesSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.cRMSubscribedDate.isEmpty() )
#set( $calcRMSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.cRMSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calcRMSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.maxDigitalSubscribedDate.isEmpty() )
#set( $calmaxDigitalSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.maxDigitalSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calmaxDigitalSubscribedDate).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( $lead.dMSSubscribedDate.equals("") )
Your DMS Subscribed is false.
#end
#if( $lead.cRMProSubscribedDate.equals("") )
Your CRM Subscribed is false.
#end
#if( $lead.bHPHSubscribedDate.equals("") )
Your BHPH Subscribed is false.
#end
#if( $lead.autoCheckSubscribedDate.equals("") )
Your AutoCheck Subscribed is false.
#end
#if( $lead.oAPSubscribedDate.equals("") )
Your OAP Subscribed is false.
#end
#if( $lead.dealerWebsitesSubscribedDate.equals("") )
Your Dealer Websites Subscribed is false.
#end
#if( $lead.cRMSubscribedDate.equals("") )
Your CRM Pro Subscribed is false.
#end
#if( $lead.maxDigitalSubscribedDate.equals("") )
Your Max Digital Subscribed is false.
#end
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...
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.
I repeat, can you prove that the property names changed when you changed the friendly field names, or are you guessing?
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.
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.
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
- 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.
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?
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.
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!!
Got it. I never knew how that was done in the community. This has been such an important lesson for me. Thanks. I edited my previous comment.
Pls highlight using the Syntax Highlighter as well.
I've copied it but indents and spacing are off so I've also attached it as is via notepad.
${display.list( $lead.entrySet(), "\u000a" )}
#if( !$lead.DMSSubscribed.isEmpty() )
#set( $calDMSSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.DMSSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calDMSSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.CRMSubscribed.isEmpty() )
#set( $calCRMSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.CRMSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calCRMSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.BHPHSubscribed.isEmpty() )
#set( $calBHPHSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.BHPHSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calBHPHSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.AutoCheckSubscribed.isEmpty() )
#set( $calAutoCheckSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.AutoCheckSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calAutoCheckSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.OAPSubscribed.isEmpty() )
#set( $calOAPSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.OAPSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calOAPSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.DealerWebsitesSubscribed.isEmpty() )
#set( $calDealerWebsitesSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.DealerWebsitesSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calDealerWebsitesSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.CRMProSubscribed.isEmpty() )
#set( $calCRMProSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.CRMProSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calCRMProSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( !$lead.MaxDigitalSubscribed.isEmpty() )
#set( $calMaxDigitalSubscribed = $convert.toCalendar(
$convert.parseDate(
$lead.MaxDigitalSubscribed,
$ISO8601,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calMaxDigitalSubscribed).getHours() >= -24 )
You subscribed to Product X within the past 24 hours.
#end
#end
#if( $lead.DMSSubscribed.equals("") )
Your DMS Subscribed is false.
#end
#if( $lead.CRMSubscribed.equals("") )
Your CRM Subscribed is false.
#end
#if( $lead.BHPHSubscribed.equals("") )
Your BHPH Subscribed is false.
#end
#if( $lead.AutoCheckSubscribed.equals("") )
Your AutoCheck Subscribed is false.
#end
#if( $lead.OAPSubscribed.equals("") )
Your OAP Subscribed is false.
#end
#if( $lead.DealerWebsitesSubscribed.equals("") )
Your Dealer Websites Subscribed is false.
#end
#if( $lead.CRMProSubscribed.equals("") )
Your CRM Pro Subscribed is false.
#end
#if( $lead.MaxDigitalSubscribed.equals("") )
Your Max Digital Subscribed is false.
#end
Pls provide the code in a way that I can test it (text, highlighted as Java).
So that's correct. I have the datatypes now correctly set. Checkmarked the Script Editor boxes for 'Subscribed' and 'Subscribed DateTime' for each product. Placed the token in an email. previewed-by-list and actually sent the email through a Smart Campaign but when received the token block is completely blank.
It feels like it's sooo close but then again without having comprehensive knowledge I may not even be close yet.
Please let me know of my next step? Here is the complete VTL.