Employee Image could not be synchronized

Hey everyone, I am working on an app similar to the “education app”, where the employee is linked to the instructor and now I want to synchronize the image of the instructor and the employee, so whenever I update the image in the employee, it will be automatically updated in the instructor and vice versa. I wrote a code to do this functionality, but it did not work, So any suggestions?

Hii @JullunarAlomari
Set up event hooks in your custom app’s hooks.py.

doc_events = {
    "Employee": {
        "before_save": "your_app.api.employee_image"
    "Instructor": {
        "before_save": "your_app.api.instructor_image"


def employee_image(doc, method):
    if doc.employee_image:
        instructors = frappe.get_all("Instructor", filters={"employee_link": doc.name}, fields=["name"])
        for instructor in instructors:
            instructor_doc = frappe.get_doc("Instructor", instructor.name)
            if instructor_doc.instructor_image != doc.employee_image:
                instructor_doc.instructor_image = doc.employee_image

def instructor_image(doc, method):
    if doc.instructor_image:
        employees = frappe.get_all("Employee", filters={"instructor_link": doc.name}, fields=["name"])
        for employee in employees:
            employee_doc = frappe.get_doc("Employee", employee.name)
            if employee_doc.employee_image != doc.instructor_image:
                employee_doc.employee_image = doc.instructor_image
1 Like

Thanks for your help. But the code I wrote was similar to yours and it does not work. I tried yours as well and changed it based on my app and fields but same problem.

This is my code

import frappe

def employee_image(doc, method):
    if doc.image:
        faculty_members = frappe.get_all("FacultyMember", filters={"employee": doc.name}, fields=["name"])
        for faculty_member in faculty_members:
            faculty_member_doc = frappe.get_doc("FacultyMember", faculty_member.name)
            if faculty_member_doc.image != doc.image:
                faculty_member_doc.image = doc.image

def faculty_member_image(doc, method):
    if doc.image:
        employees = frappe.get_all("Employee", filters={"faculty_member": doc.name}, fields=["name"])
        for employee in employees:
            employee_doc = frappe.get_doc("Employee", employee.name)
            if employee_doc.image != doc.image:
                employee_doc.image = doc.image

# Triggering functions before save
def attach_hooks():
    frappe.db.before_save("Employee", employee_image)
    frappe.db.before_save("FacultyMember", faculty_member_image)

# Call the function to attach hooks when the app is installed
def after_install():