Sever Script: Check if fields changed?

I have a custom App that will use the Google Geocode API to geocode and address field to get the latitude/longitude.

I only want to call the API if the address field is being changed.

Is there a way within frappe to check if a field is being changed?

old_doc = doc.get_doc_before_save()
if old_doc.price != doc.price:
    # price changed
    pass

https://frappeframework.com/docs/user/en/api/document#doc-get-doc-before-save

1 Like

Late to the party, but you can also use has_value_changed.

if self.has_value_changed('field_name'):
    do_your_magic_here

If you want to check if something is changed in the child table then use is_child_table_same.

if not self.is_child_table_same("items"):
    frappe.msgprint('Items has been changed')
  
4 Likes