CMS Development

PKemps
Contributor

Event calendar in email with upcoming events

SOLVE

Hi, i hope that someone can help me.

 

I'm creating a event calendar module to be used in email with the next 3 upcoming events. I created some custom properties for that and a custom emailmodule. But now i trying to filter only the upcoming events.

 

This piece of code filters the 3 marketing events and that works:

{% set events = crm_objects("marketing_event", "limit=3&orderBy=event_start_date") %}

 

I want to add a filter to the "set" for the upcoming events like: &unixtimestamp(local_dt) < event.event_start_date. 

 

I cannot get this to work. So i pprint some data:

  • event_start_date: (String: 26-10-22)
  • unixtimestamp(event.event_start_date.value): (Long: 1675423920776)
  • local_dt: (PyishDate: 2023-02-03 12:32:00)
  • unixtimestamp(local_dt): (Long: 1675423920663)
  • local_dt|format_date('dd-MM-yy'): (String: 03-02-23)

 

It looks that the unixtimestamp(event.event_end_date.value) creates a current timestamp instead that of the value of event_end_date of 26-10-2022. 

 

I hope that someone can help.

 

 

 

1 Accepted solution
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Event calendar in email with upcoming events

SOLVE

Hi @PKemps,

 

Like we discussed, here is the solution to the question 😜;

{% set current_date = unixtimestamp(local_dt) %}
{% set query = "limit=3&orderBy=custom_end_date&custom_end_date__gte="~current_date %} 
{% set events = crm_objects("marketing_event", query, "hs_event_name,custom_end_date", false) %}

{% for item in events.results %}
  <p>
   {{item.hs_event_name}}
  </p>
{% endfor %}

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

0 Upvotes
10 Replies 10
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Event calendar in email with upcoming events

SOLVE

Hi @PKemps,

 

Like we discussed, here is the solution to the question 😜;

{% set current_date = unixtimestamp(local_dt) %}
{% set query = "limit=3&orderBy=custom_end_date&custom_end_date__gte="~current_date %} 
{% set events = crm_objects("marketing_event", query, "hs_event_name,custom_end_date", false) %}

{% for item in events.results %}
  <p>
   {{item.hs_event_name}}
  </p>
{% endfor %}

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


0 Upvotes
Cereno-Deng
Contributor

Event calendar in email with upcoming events

SOLVE

Hi @PKemps - You might need to use unixtimestamp(event.event_start_date) not unixtimestamp(event.event_start_date.value). The unixtimestamp() will return current timestamp when it can't convert the datetime object.

0 Upvotes
PKemps
Contributor

Event calendar in email with upcoming events

SOLVE

When i use unixtimestamp(event.event_start_date) pprint prints nothing.

0 Upvotes
Cereno-Deng
Contributor

Event calendar in email with upcoming events

SOLVE

Your even.event_start_date is datetime or string type? It must be datetime type to make unixtimestamp work.

0 Upvotes
PKemps
Contributor

Event calendar in email with upcoming events

SOLVE

Thanks for your respons. It is a date picker property. But the unixtimestamp(event.event_start_date.value) pprint current date and not the right date value of the property and unixtimestamp(event.event_start_date) pprint prints nothing.

0 Upvotes
Cereno-Deng
Contributor

Event calendar in email with upcoming events

SOLVE

I created a test environment like yours and get the same issue.  The problem is no correct way to convert the string to datetime pbject. The strtotime filter only convert string like "yyyy-MM-dd'T'HH:mm:ssZ".

 

For example,  the {{ "26-10-22"|strtotime("dd-MM-yyyy") }} will get error "Error in `Marketplace/HubSpot/HTML/Custom Module/HTML.module/module.html` on line 3: com.hubspot.jinjava.interpret.InterpretException: stringToTime() could not match datetime input 26-10-22 with datetime format dd-MM-yyyy" shown in the browser DevTools. Many people also get this issue like this discussion.

 

So I think the better way is to convert custom object to HubDB table. I am sure the column with date type can be converted to timestamp normally by unixtimestamp(). You can see this to know how to convert/sync custom object with HubDB table.

 

 

0 Upvotes
PKemps
Contributor

Event calendar in email with upcoming events

SOLVE

Hi Cereno-Deng, we only have marketing Pro, so i have no options for HubDB and programmable actions in workflows. But thanks that you looked into it.

0 Upvotes
Cereno-Deng
Contributor

Event calendar in email with upcoming events

SOLVE

Hi Paul,

 

I have an idea. You can change the event_start_date type to string, create a admin page for marketing_event custom object to call the backend APIs on your server to create/update them. In the backend API, you can convert start date to the correct format strtotime filter can accept, and call the CRM API for custom objects. So it should work on your calendar module: {% set start_date = unixtimestamp(event.event_start_date|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")) %}

 

Cereno

PKemps
Contributor

Event calendar in email with upcoming events

SOLVE

Hi Cereno-Deng, i'm not so familiar with api. I will ask our IT-department if they can help me. Thanks.

Jaycee_Lewis
Community Manager
Community Manager

Event calendar in email with upcoming events

SOLVE

Hi, @PKemps 👋 Thanks for sharing your question. Hey, @Anton @tominal @JBeatty have you dared to navigate down this particular road for email templates? 

 

Thanks for taking a look! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot