Adding filters to link

My friends have two fields of type link, first field parent_department father and second field
I want to choose when the first field, but the entity appears in the second field sub-entities of the first field
You participate if you kindly

Since I did this code and did not fit
frappe.ui.form.on (“divorce_certificates”, “parent_department”, function (frm) {
if (frm.doc.parent_department == “parent_department”)
set_field_options (“department_name”, [“doc.department_name”])

Why don’t you use doc.department as link and department _name as department name from the actual link of department.

Why so you want to have 2 link field of the same doctype?

Maybe this is what you mean, for the rest can use filters

	frm.set_query("department_name", function() {
		return {
			filters: {
				"parent_department": frm.doc.parent_department,

Please solved if your problem is resolved