SOLVED

Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

Go to solution
R-Par
Level 2

Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

Hi,

Using Velocity Script, how can I separately retrieve Date, Month and Year values from a datetime field from a custom object? 

Example:

We want to send a weekly email to those who complete at least one course in the last week. The third party integration sends data to Marketo every Sunday and the email should go out in 1 hour of sync to those who completed the course. 

We want to create a velocity script for this case to run auto-sending email every week (without any manual date updates in the script). We have below 2 questions:

1) 

Seems like we would need to compare 2 datetime fields, while ignoring timestamp values. 

  • "updated at" field in the CO - which captures the time when the sync occurs; and
  •  system datetime

2) 

We need to run a one-time email to catch up with the previous users who completed course/s. Here, we would need to compare 2 datetime fields, again, while ignoring timestamp values. 

  • "updated at" field in the CO - which captures the time when the sync occurs; and
  •  specific past date

I am looking for code samples for this.

 

TYIA 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

Seems you’re over-concentrating on “ignoring timestamp values” — what you want is the difference in days between two dates. (No reason to specifically mention time values, just like if you were computing the difference in years you wouldn’t need to talk about days or hours. Concentrate on the time unit you want and it’s implied that you don’t care about other units!)

 

But before we continue, I want to confirm: are you trying to qualify people for an email send based on Velocity? That won’t work. Velocity runs after the person qualifies — it can dramatically personalize output and incorporate custom object data, but Velocity can’t decide whether someone gets an email. You qualify people based on Smart List rules.

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

Seems you’re over-concentrating on “ignoring timestamp values” — what you want is the difference in days between two dates. (No reason to specifically mention time values, just like if you were computing the difference in years you wouldn’t need to talk about days or hours. Concentrate on the time unit you want and it’s implied that you don’t care about other units!)

 

But before we continue, I want to confirm: are you trying to qualify people for an email send based on Velocity? That won’t work. Velocity runs after the person qualifies — it can dramatically personalize output and incorporate custom object data, but Velocity can’t decide whether someone gets an email. You qualify people based on Smart List rules.

R-Par
Level 2

Re: Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

Hi Sanford, Darshil and Thorsten,

 

Thank you for your inputs.

Checking in quite late here. But to circle back on the follow-up queries:

The idea was to bring the course name in the email dynamically via velocity script, while the email will definitely be sent via smart campaign. The current script is working now - brings every name that completed a course in a given week - but still needs change of date to be done manually in the script - every week.

Focus on date comparison is high since we have past completions that we want to target for sending emails + weekly batch emails for the new completions. Bit tricky to type and explain here.

Apology for the confusion and totally appreciate your replies.

 

Best
Ridhdhi

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

For sending out emails to the records via the batch campaign, I think you could use the Was Added to CO filter with date-time field <> empty. This filter would allow you to reference the date of activity constraint for the addition of the CO record activity for the people. Along with this filter, you should also combine the Has CO filter in an AND operation to ensure that the respective person still has a non-empty value for the date-time/course/etc. fields. You could also use the apt operator in the date-time CO field (by adding the field as a constraint in the filter) to ensure the value is in the past x days as required by your use case. You can then reference the course details data in the email using the velocity.

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

As Sandy very correctly articulates, with velocity you can only query data from standard and custom object fields and customize your email dynamically for a person based on their data/conditions match/etc., (there's one poison pill use-case as well, using which you can cease an email going out to a person based on certain conditions). Velocity certainly, cannot be used to schedule/trigger off emails to people; you gotta use the Marketo SC for that.

 

For your particular use case, unless I'm not missing out on anything, it seems like you would need to use CO SL triggers/filters (Added/Updated records) for identifying the audience and use a wait step in the flow if you'd like to wait for a certain duration (as you said 1 hr in your case) before sending out the email.

Thorsten
Level 4

Re: Velocity Script: Retrieve only date values from a "datetime" type of a Custom Object field

Alternatively, you can still "brute-force" stop the email send via Velocity, as explained by Sanford. But you probably don't have to go that far.