Hello community members,
I am trying to retrieve the actual database values within the on_update
method.
Expectation When I select specific records from the list view and navigate to the edit page, I make changes to a few fields. I want to compare the newly entered values with the existing database values inside the on_update
method on save button click. I write get_doc method and try to get the actual DB value
Result To my surprise, both get_list
and get_doc
merge the results with the form values and return them, meaning the result contains the form values rather than the actual database values for the specific record. However, the database hasn’t been updated yet. I simple couldt get the actual DB values inside the on_update mehtod but I can get the actual DB values on seperate bench console while having debug set on this line
def on_update(self):
print(' ************* on_update ***************')
get_fields = ['name', 'branch_id', 'category', 'item', 'standard_stock', 'price']
result_list = frappe.db.get_list('Asset Master',
filters={},
fields=get_fields)
# return DB values with the form value merged for this specific record
print(result_list)
res_doc = frappe.get_doc('Asset Master', '13')
# return DB values with the form value merged for this specific record
print(res_doc.name, res_doc.price)
Any changes I make to the fields are reflected when calling get_list
and get_doc
.
What might be wrong with my approach? I would greatly appreciate any assistance.