Department in Salary Slip

Hi,
I want to set permissions on Salary Slip based on Department,
But the default department field in Salary Slip is Read Only field, as we know that Permissions only relay on Link fields as data type, so, i change the field type of Department from Read Only to Link.
But now the problem is, when creating salary slips via Payroll Process / Payroll Entry, Salary slips generates automatically with All details, including company with the Link field. but we’ve to choose the department manually,

I want to set department automatically as same as company is setting up automatically without opening the salary slip,
can someone guide me that how to achieve this?
& I think this is very important, ERPNext should include this feature by default including BRANCH & DEPARTMENT both.

frappe.ui.form.on("Salary Slip", "onload", function(frm) {
    frappe.call({
        "method": "frappe.client.get",
        "args": {
             "doctype": "Employee",
             "name": frm.doc.employee
        },
        "callback": function(response) {
             var employee = response.message;
             if (employee) {
                  frm.set_value('department', employee.department);
		
             } else {
                  frappe.msgprint("Employee not found");
            }
        }
    }); 
})

I’ve also tried this script but this is working only when we opens the Salary slip.

Any update?