I’m working with a Zapier automation that syncs data from Airtable to a MySQL database. The workflow has two branches - one creates new records when they don’t exist, and the other updates existing records with fresh data from Airtable.
The update process works perfectly when replacing existing data with new values. For example, this record updates correctly:
+--------+-------------+------------------+
| rec_id | user_notes | airtable_ref_id |
+--------+-------------+------------------+
| 234 | good | 8765432109876 |
+--------+-------------+------------------+
When the user changes the note, it updates to:
+--------+-------------+------------------+
| rec_id | user_notes | airtable_ref_id |
+--------+-------------+------------------+
| 234 | excellent | 8765432109876 |
+--------+-------------+------------------+
However, when a user clears the field completely in Airtable, the MySQL record doesn’t get updated. The old value stays there instead of being cleared.
I need it to look like this when the field is empty:
+--------+-------------+------------------+
| rec_id | user_notes | airtable_ref_id |
+--------+-------------+------------------+
| 234 | | 8765432109876 |
+--------+-------------+------------------+
After testing and talking to Zapier support, it seems the issue is that null values get stripped from the Code step output, so the MySQL update step doesn’t see any change to make.
Here’s my Python code for processing the inputs:
# Handle missing inputs with empty values
def process_field(field_name):
return source_data.get(field_name, default_value)
def map_all_fields(field_list, mapping_list):
for source_field, target_field in zip(mapping_list, field_list):
val = process_field(source_field)
output_data.update({target_field: val})
source_fields = ['field_machine', 'field_start', 'field_end', 'field_details', 'field_vendor', 'field_scheduled', 'field_approved', 'field_ref', 'field_done', 'field_quote', 'field_invoice', 'field_receipt', 'field_record', 'field_modified', 'field_user_notes']
target_fields = ['machine', 'start', 'end', 'details', 'vendor', 'scheduled', 'approved', 'ref', 'done', 'quote', 'invoice', 'receipt', 'record', 'modified', 'user_notes']
# Process all field mappings
default_value = None
output_data = {}
map_all_fields(target_fields, source_fields)
final_results.update(output_data)
return final_results
The code runs without errors and updates work fine when there’s actual new data, but empty fields don’t clear the old MySQL values. Has anyone found a way to make Zapier MySQL updates handle empty values properly?