Hello,
I created a workflow that checks:
- if a contact ever had a meeting booked? (regardless of the outcome)
- The date of the first meeting that was actually held with the contact (outcome = Completed)
It has this custom code action:
from datetime import datetime
import logging
def main(event):
# Initialize placeholders
has_meetings_booked = False
first_meeting_date = None
# Extract input data
meetings_data = event["inputFields"].get("meeting_details", [])
# Log the raw data for debugging
logging.debug(f"Raw Meeting Details: {meetings_data}")
# Check if there are any meetings
if isinstance(meetings_data, list) and meetings_data:
has_meetings_booked = True
# Filter for completed meetings with valid start_date
completed_meetings = [
m for m in meetings_data
if m.get("outcome") == "Completed" and m.get("start_date")
]
# Log completed meetings
logging.debug(f"Completed Meetings: {completed_meetings}")
# If there are completed meetings, find the earliest start_date
if completed_meetings:
try:
earliest_date = min(
datetime.fromisoformat(m.get("start_date"))
for m in completed_meetings
)
# Set the time to midnight (UTC)
earliest_date_midnight = earliest_date.replace(hour=0, minute=0, second=0, microsecond=0)
first_meeting_date = earliest_date_midnight.isoformat() + "Z"
except ValueError as e:
logging.error(f"Date Parsing Error: {e}")
first_meeting_date = None
# Return the outputs
return {
"outputFields": {
"has_meetings_booked": has_meetings_booked,
"first_meeting_date": first_meeting_date,
}
}
When I test it, is says that “has_meetings_booked = False” and “first_meeting_date” is invalid, even though the contact has two meetings, one scheduled and the other completed.
What can I be doing wrong?







