SOLVED

Re: Building a birthday / anniversary email without using Wait Step > Next Anniversary

Go to solution
Megan_Koelemay
Level 4

Hi there, 

 

I'm aware of how to build birthday / anniversary emails using a date token in a wait flow step, as outlined here: https://experienceleague.adobe.com/docs/marketo/using/product-docs/core-marketo-concepts/smart-campa...

 

But I would like to avoid using such a long wait step, in case there are unexpected changes in the data during that time.  We ran into this problem in a past iteration of our birthday emails - for example, an incorrect or fake Date of Birth was entered in our CRM, and then was corrected at a later date.  Since the campaign was in a wait step, the correction didn't register, and a birthday email was delivered on the wrong day.  

 

Anyone know of a way to get around this?  I basically want to do a daily batch campaign like this:

  • If the anniversary of the Date of Birth is today, then send email.  

Our IT/Systems staff (non-Marketo users) suggested this:

  • Create a new field that is the birthday anniversary for their next b-day. Then we could have a smartlist that searches to see that today is a match for that field. That field would need to be updated any time the birthday is updated or after the campaign is run. I would hope the campaign could update the anniversary field to next years date after it sends the email but I’m not sure if that’s an action that can be in the flow.

Thoughts/ideas?

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator



@SanfordWhiteman wrote:

Then use Change Data Value to set Next Anniversary Date to {{lead.Next Anniversary Date}} + 1 year.


So if I'm understanding the portion above correctly, that takes care of ensuring the birthday campaign continues to run year after year.  


Right.

 



For the new field, should I set the field type to Date?

 

My challenge now is how to get the anniversary date in the first place.  The only field we have to work with is Date of Birth, which obviously includes the year of birth and can't be used as an anniversary.  I've seen suggestions in the forums that a webhook can be used to achieve this.  I haven't used webhooks before, so was hoping for a Marketo solution.  But hey, always fun to learn something new!  


Yep.

 


My challenge now is how to get the anniversary date in the first place.  The only field we have to work with is Date of Birth, which obviously includes the year of birth and can't be used as an anniversary.  I've seen suggestions in the forums that a webhook can be used to achieve this.  I haven't used webhooks before, so was hoping for a Marketo solution.  But hey, always fun to learn something new!  


True. If your external system can’t start it off on the right date, your challenge is to initialize the field to the first anniversary date after today, after which it’ll run automatically. There’s no way to do this with only internal Marketo functions. A webhook-compatible service can do it quite easily. For example if your service runs/understands JS, the code could be like so:

let today = new Date();
let dateOfBirth = new Date({{Lead.Date of Birth}});
var nextBirthday = new Date(dateOfBirth);

nextBirthday.setYear(today.getFullYear());
if( nextBirthday < today ) {
  nextBirthday.setYear(nextBirthday.getFullYear() + 1);
}

 

This makes a clone of the Date of Birth, then sets its year to the current year. That is, if my birthday is 2010-06-01, then the clone is 2022-06-01.  Then it does a final check to see if the clone is in the past (i.e. earlier this year) and if so, pushes it forward one more year. After that it’s good to go.

View solution in original post

21 REPLIES 21
SanfordWhiteman
Level 10 - Community Moderator

I don't like the Wait method either - no matter how common - for the reasons you note.

 

You can have a field named Next Anniversary Date and run a batch exactly as you say. Then use Change Data Value to set Next Anniversary Date to {{lead.Next Anniversary Date}} + 1 year.

Megan_Koelemay
Level 4

Thanks @SanfordWhiteman!  I didn't realize until today when I stumbled upon this other post with your reply that the + [timeframe]  is a possibility!!  And your application above is brilliant! 

 


@SanfordWhiteman wrote:

Then use Change Data Value to set Next Anniversary Date to {{lead.Next Anniversary Date}} + 1 year.


So if I'm understanding the portion above correctly, that takes care of ensuring the birthday campaign continues to run year after year.  

 


@SanfordWhiteman wrote:

You can have a field named Next Anniversary Date 


For the new field, should I set the field type to Date?

 

My challenge now is how to get the anniversary date in the first place.  The only field we have to work with is Date of Birth, which obviously includes the year of birth and can't be used as an anniversary.  I've seen suggestions in the forums that a webhook can be used to achieve this.  I haven't used webhooks before, so was hoping for a Marketo solution.  But hey, always fun to learn something new!  

SanfordWhiteman
Level 10 - Community Moderator



@SanfordWhiteman wrote:

Then use Change Data Value to set Next Anniversary Date to {{lead.Next Anniversary Date}} + 1 year.


So if I'm understanding the portion above correctly, that takes care of ensuring the birthday campaign continues to run year after year.  


Right.

 



For the new field, should I set the field type to Date?

 

My challenge now is how to get the anniversary date in the first place.  The only field we have to work with is Date of Birth, which obviously includes the year of birth and can't be used as an anniversary.  I've seen suggestions in the forums that a webhook can be used to achieve this.  I haven't used webhooks before, so was hoping for a Marketo solution.  But hey, always fun to learn something new!  


Yep.

 


My challenge now is how to get the anniversary date in the first place.  The only field we have to work with is Date of Birth, which obviously includes the year of birth and can't be used as an anniversary.  I've seen suggestions in the forums that a webhook can be used to achieve this.  I haven't used webhooks before, so was hoping for a Marketo solution.  But hey, always fun to learn something new!  


True. If your external system can’t start it off on the right date, your challenge is to initialize the field to the first anniversary date after today, after which it’ll run automatically. There’s no way to do this with only internal Marketo functions. A webhook-compatible service can do it quite easily. For example if your service runs/understands JS, the code could be like so:

let today = new Date();
let dateOfBirth = new Date({{Lead.Date of Birth}});
var nextBirthday = new Date(dateOfBirth);

nextBirthday.setYear(today.getFullYear());
if( nextBirthday < today ) {
  nextBirthday.setYear(nextBirthday.getFullYear() + 1);
}

 

This makes a clone of the Date of Birth, then sets its year to the current year. That is, if my birthday is 2010-06-01, then the clone is 2022-06-01.  Then it does a final check to see if the clone is in the past (i.e. earlier this year) and if so, pushes it forward one more year. After that it’s good to go.

Megan_Koelemay
Level 4

Also, any recommendations for webhook / webhook-compatible services?  

 

Jo_Pitts1
Level 10 - Community Advisor

@Megan_Koelemay ,

I will recommend FlowBoost.  @SanfordWhiteman can't because he wrote it.

 

I use it regularly.  It is brilliant.

 

Cheers

Jo

SanfordWhiteman
Level 10 - Community Moderator

Indeed Jo, and here’s how you’d Set a Date field to the next anniversary of another Date using FlowBoost. (Using built-in JS methods that could be used in other contexts as well.)

Megan_Koelemay
Level 4

I'm (finally) returning to this webhook option for calculating someone's next birthday based off of their Date of Birth field so I can send birthday emails from Marketo.  I got set up with FlowBoost (yay!) and am now using Postman as a lab environment for testing the code before setting the Marketo / FlowBoost webhook, as recommended in the FlowBoost documentation.  I'm not very familiar with JavaScript, though, so I'm running into a challenge.  

 

My fields/variables in Postman are identical to my Marketo fields and are set up like this:

lead.Date of Birth

lead.Birthday Anniversary

 

Using @SanfordWhiteman's code above as a template (THANK YOU!!), I've tried replacing the "nextBirthday" references with my {{lead.Birthday Anniversary}} variable but I'm getting errors.  Any thoughts on what I'm doing wrong?  I'm sure I've got some buggy syntax in here somewhere!

 

Megan_Koelemay_0-1646853583154.png

 

Megan_Koelemay
Level 4

I tried a couple changes, and I'm not sure if this is what fixed it or not, but I changed the capital "L" to "l" in line 6 so now it's {{lead.Date of Birth}}.  This gave me a correct result:

 

// Get today at midnight UTC
let today = new Date();
["setUTCHours","setUTCMinutes","setUTCSeconds","setUTCMilliseconds"].forEach( unitSetter =>  today[unitSetter](0) );

// Convert original DOB to Date
let dateOfBirth = new Date({{lead.Date of Birth}});

// Clone the DOB to a new Date for clarity
var birthdayAnniversary = new Date(dateOfBirth);

// First, set to the same day in the current year 
birthdayAnniversary.setYear(today.getFullYear());

// Only if birthdayAnniversary is still in the past, set one more year forward
if( birthdayAnniversary < today ) {
  birthdayAnniversary.setYear(birthdayAnniversary.getFullYear() + 1);
}
SanfordWhiteman
Level 10 - Community Moderator

Postman environment variables are definitely case-sensitive, so that makes sense.

Megan_Koelemay
Level 4

@SanfordWhiteman, I've got my webhook set up in Marketo now using the code above, but am running into an odd problem - the resulting birthday anniversary is a day off:

 

Megan_Koelemay_0-1646862371943.png

The webhook response in the Activity Log details says {"birthdayAnniversary":"2023-02-01T00:00:00.000Z"}.  Is there something about the midnight UTC calculation that's confusing Marketo when it comes to the user-friendly presentation of this date?

 

SanfordWhiteman
Level 10 - Community Moderator

The webhook response in the Activity Log details says {"birthdayAnniversary":"2023-02-01T00:00:00.000Z"}.  Is there something about the midnight UTC calculation that's confusing Marketo when it comes to the user-friendly presentation of this date?


Yes and no — I mean, it’s not confused per se because if your time zone is behind UTC, it is the day before. If your timezone is ahead of UTC, it’ll reflect that day.

 

If you want Marketo to set its local timezone you could add

var nextBirthdayDateOnly = nextBirthday.toLocaleDateString("se");

to the end and map nextBirthdayDateOnly in Response Mappings.

Megan_Koelemay
Level 4

Worked like a charm - thanks!!

llckll
Level 1

I have a question about the proper way to CC your colleagues about anniversary email.


Example:

 

It's Charlie's 10 year work anniversary. I have Marketo send out an anniversary email to the person every year.

 

What I'm trying to do is also CC people on my employee list regarding Charlie's anniversary. In other words, Charlie gets his anniversary email but I want the rest of the employees to get the same Charlie personalized email.

 

Unclear how to send out personalized email to rest of employees without using their own personalization if that makes sense.


Thanks.

SanfordWhiteman
Level 10 - Community Moderator

Use Send Alert. In "To other emails" you can enter any other email addresses.

 

You can also use a {{lead.token}} (or any token) there, but you need to be in a Trigger Campaign context for that to work. (A Batch Campaign that calls Request Campaign on a Trigger Campaign is fine.)

llckll
Level 1

OK, so it sounds like I can create a local token and add the email addresses in the token instead of having to copy and paste 55 emails in the "To Other Emails" section.

 

Thanks, will give it a go!

Megan_Koelemay
Level 4

Ah!  Thanks for the rec, @Jo_Pitts1!

SanfordWhiteman
Level 10 - Community Moderator

Also, any recommendations for webhook / webhook-compatible services?  

Alas, no, due to Community guidelines.

Megan_Koelemay
Level 4

Thanks @SanfordWhiteman!  Appreciate the code and explanation!!

 

Thinking about the wait step w/anniversary option again - I wonder if it would work to set up a separate triggered campaign so if there's a data value change on the Date of Birth, then it would remove someone out of the birthday campaign wait step and re-enter them into it using the new date.  Like this:

 

Smart List:

Trigger --> Data Value Changes, Attribute: Date of Birth

 

Flow:

1 - Remove From Flow --> Campaign is [Happy Birthday Email]

2 - Request Campaign  --> Requested Campaign is [Happy Birthday Email]

SanfordWhiteman
Level 10 - Community Moderator

Right, this is how you can recycle them through the campaign, but it doesn't get away from the Waits.

Megan_Koelemay
Level 4

Wouldn't the combination of the wait step w/anniversary option and a campaign setting of allowing each person to run through the flow only once every 364 (or 365??) days do the trick of recycling?