Using Validate (server script) On Item group field in Item

Hi All,
I want to write code to work as a field trigger in (client script) but using server script,

my case is triggered when the item group field in the item is changed I want to run some functionality in the server script.

Is there any help?

item_group = doc.item_group

if doc.item_group != item_group:
    frappe.msgprint(_("Item Group is changed."))

I need something like this because it is not working for me
@NCP kindly is there any way

Hmm :thinking:,

Please try it @Omar_Mohammed.

    previous_item_group = doc.get_db_value('Item', doc.name, 'item_group')

    if previous_item_group != doc.item_group:
        frappe.msgprint(_("Item Group is changed."))

Thank You!

Thank you for response

but I face this, and I search for documentation for get_db_value function
image

import frappe

def on_update(doc, method):
    previous_item_group = doc.get_db_value('Item', doc.name, 'item_group')
    if previous_item_group != doc.item_group:
        frappe.msgprint(_("Item Group is changed."))

Please add doc_event in hook.py in custom app and set code your according.

Thank You!

I face a same error message

TypeError: BaseDocument.get_db_value() takes 2 positional arguments but 4 were given

Is get_db_value built-in or officially documented function?

You can try this!

1 Like

I found this

I also try frappe.db.get_value but it’s not returen before the change is getting the value after the change

yes, it is.

Thank you so much it’s working as I want.

Thank you for your help @NCP

No worries!

1 Like