Check field exist in erpnext python script

Hi,
I need to update custom fields in all document on event before_insert and before_submit,
Since these fields not exist in some doctype ,i need to check the existence for the field before assigning them.
How to check for field existence for the active document in erpnext python?
Thanks

HI,
I just find a way
I do :

doc.custom_fields = value

in a ‘try except block’ and give a ‘pass’ in the exception
it works fine.

Thanks

I use
if hasattr(docCustomer, 'taxoffice'):

1 Like

Hi TurkerTunali,
Thanks for your reply, I will definitely keep you solution for my reference

meta = frappe.get_meta(“Item”)

print(meta.has_field(‘my_custom_field’)) # returns True or False.

print(meta.get_custom_fields()) # returns a list of all custom fields.