custom coded Workflow not updating outputs correctly
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.
custom coded Workflow not updating outputs correctly
@IDevolé - all I can see is a rather trivial issue of an extra comma at the end of the outputFields JSON definition. I can't exactly reproduce what's happening here, but its clearly essential to get the output block return value definitions exactly matching the outputField{} setup.
custom coded Workflow not updating outputs correctly
Are you still having trouble with this custom code action, @IDevolé?
I tested this code in my own workflow using the tester and I see the same warning on the output: Make sure to define the output "has_meetings_booked" in the outputFields block in the code using the same name you used in the data outputs form.
I want to offer a couple of similar threads that may point you to some follow up steps: