Data Outputs Not Working

ahmedbs
Member

from datetime import datetime
maintDate = ''
def main(event):
try:
input_fields = event.get('inputFields')

# Get the maintenance start and end dates
maint_start_date = input_fields.get('maint_start_date')
maint_end_date = input_fields.get('maint_end_date')

# Check if the dates are not None and are valid datetime objects
if maint_start_date is None or maint_end_date is None:
raise ValueError("Maintenance start date or end date is missing.")

# Assuming the dates are in string format, convert them to datetime objects
maint_start_date = datetime.strptime(maint_start_date, '%Y-%m-%d')
maint_end_date = datetime.strptime(maint_end_date, '%Y-%m-%d')

# Format the dates as strings
maintDate = maint_start_date.strftime('%Y-%m-%d') + " to " + maint_end_date.strftime('%Y-%m-%d')

return {
"outputFields": {
"maintDate": maint_date
}
}
except Exception as e:
return {
"error": str(e)
}

With this above code, in the Data Outputs when I test the flow it gives me error maintDate is not defined in code.

ahmedbs_0-1733235357514.png

 

0 Upvotes
1 Accepted solution
PamCotton
Solution
HubSpot Alumni
HubSpot Alumni

Hey @ahmedbs, thank you for posting in our Community!

 

Looks like the issue lies in the variable name mismatch in your return statement. You defined the variable as maintDate but returned it as maint_date. Python is case-sensitive, so maintDate and maint_date are treated as different variables.

 

@Anton and @DanielSanchez do you have any recommendations for @ahmedbs matter?

 

Thank you,

Pam

View solution in original post

0 Upvotes
2 Replies 2
PamCotton
Solution
HubSpot Alumni
HubSpot Alumni

Hey @ahmedbs, thank you for posting in our Community!

 

Looks like the issue lies in the variable name mismatch in your return statement. You defined the variable as maintDate but returned it as maint_date. Python is case-sensitive, so maintDate and maint_date are treated as different variables.

 

@Anton and @DanielSanchez do you have any recommendations for @ahmedbs matter?

 

Thank you,

Pam

0 Upvotes
ahmedbs
Member

Thanks Pam! The code got too messy and need to clean it up and figure out.