SOLVED

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

Go to solution
Jo_Pitts1
Level 10 - Community Advisor

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

@Megan_Koelemay ,

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

 

I use it regularly.  It is brilliant.

 

Cheers

Jo

Megan_Koelemay
Level 4

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

Ah!  Thanks for the rec, @Jo_Pitts1!

SanfordWhiteman
Level 10 - Community Moderator

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

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

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

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

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

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

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

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

Megan_Koelemay
Level 4

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

@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

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


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

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

Worked like a charm - thanks!!

llckll
Level 1

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

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.