3 Replies Latest reply on May 13, 2016 8:11 AM by Scott McKeighen

    "Next Date" type token using scripting?

      Hi there,

       

      I am trying to set up a series of emails where the CTA is to "join us for a demo on _____."  What I'd like to do is set up some kind of token that just automatically inserts whatever the next demo date is.

       

      Has anyone been able to do this successfully? I'm thinking the only route is through email scripting -- if you have been able to make it work, would you mind providing your script as an example? Unfortunately, my 'coding' knowledge stops at the basics. I sort of understand the developer article on scripting, but not enough to actually attempt it.

       

      Also, if there is a better way, I am open to suggestions!

       

      Thank you in advance for any help!

        • Re: "Next Date" type token using scripting?
          Scott McKeighen

          Hi Rachel,

           

          The answer really depends on the needed level of sophistication in the email.

           

          Is that value in your email always going to be a specific day and time in the future that's unique to the program (like join us for a demo on May 27th), or do you want to automatically calculate a 'next demo' value with some date math and display that?

           

          If it's the former, one method would be to make a program level text token, such as '{{my.NextDemoDate}}' and put a value there appropriate to the demo email you're sending. You'd have to make editing that token value part of your email development process. This relies exclusively in human input, so it has the benefits and drawbacks associated with that.

           

          If it's the latter, Velocity Script is a good method. Here's one we use to dynamically calculate a 'start date' for one of our programs.

           

          #set($x = $date.toDate("MMM d, yyyy", $lead.SamplePilotProgramStartDate))

          #set($dayOfWeek = $date.format('E', $x))

          #set($y = $date.toCalendar($x))

           

          #if ( $dayOfWeek == "Thu" )

          ## Add 96 hours

          $y.add(10,96)

           

          #elseif ( $dayOfWeek == "Fri" )

          ## Add 96 hours

          $y.add(10,96)

           

          #elseif ( $dayOfWeek == "Sat" )

          ## Add 72 hours

          $y.add(10,72)

           

          #else

          ## Add 48 hours

          $y.add(10,48)

          #end

           

          ## Writes the date

          #set($z = $date.format('MMMM dd, yyyy', $date.toDate($y)))

           

          ## Show end result

          $z

           

          In a nutshell the script is a big ELSE IF statement that loops through to change the output that gets displayed in the token. We detect what day it is when the Marketo trigger executes the email send, and conditionally change the output. Right now, this script keys off of a specific custom field, "SamplePilotProgramStartDate," the value of which we establish via form fill. But that can be practically anything you want. Also note that you probably don't need to be as specific as we are with the #elseif clauses for Thursday, Friday, and Saturday, so feel free to modify the script as necessary.

           

          Hope that helps! If you have any questions, feel free to reach out.

          1 of 1 people found this helpful
            • Re: "Next Date" type token using scripting?

              Thanks Scott! I think the Velocity script looks like our best bet. Our team is tiny so I am/was attempting to make it 'set it and forget it'!


              However, the more I'm thinking about it the more I'm realizing what I had hoped to achieve may not be possible. We currently have a drop down list that allows folks to register for whatever date works best for them. What I was trying to figure out was how to get the token to look at that list and insert the closest date into the email.

               

              If you have any insight on whether that is doable or not, a second opinion would be great. Luckily I have some time to fiddle with it.

               

              Thanks again!