How to fetch active user department automatically in the doctype field

If you want to add the active user department in the doctype automatically just add one field where you want to add the department and add the following server script in the doctype connections.

test = frappe.db.sql(“”" select from tabDepartment as d join tabEmployee as e on e.department = where e.user_id=%s “”", frappe.session.user);
doc.field name = test