I am having an issue with my code in Zapier
application. I have written a fairly simple if, elif
, and I am drawing incorrect outputs. If I declare the variables as or
the code works, but when using input.get
which is a requirement, the code will always answer both even if the values are null
.
The goal of the program is to determine if an item has a phone number, email or both. Any thoughts? I am fairly new to Python and code by Zapier so I am sure this is simple.
phoneTest = input.get('Phone')
emailTest = input.get('Email')
if(emailTest != '') and (phoneTest != ''):
logic = 'both'
elif(emailTest == '') and (phoneTest != ''):
logic = 'phone'
elif(emailTest != '') and (phoneTest == ''):
logic = 'email'
output = [{'test': emailTest}]
Python code in Zapier:
even if the values are null
Your code is checking specifically against the empty string, not null (None). So yes, if the items are null, its going to say both. Try doing a "truthy" check instead of specifically the empty string.
phoneTest = input.get('Phone')
emailTest = input.get('Email')
if emailTest and phoneTest:
logic = 'both'
elif phoneTest:
logic = 'phone'
elif emailTest:
logic = 'email'
output = [{'test': emailTest, 'logic': logic}]