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.
feb 4, 202312:17 AM - editado feb 4, 202312:19 AM
Colaborador
Event calendar in email with upcoming events
resolver
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.
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.
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.
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")) %}