How to Display the Employees in a Branch once the Branch is Selected

Hello, I will need help with a code to display the employees in a particular branch once the branch is selected. The employee will be displayed on a child table row by row. Thanks

Hello Kindly change the field in the below sample code as per your doctype

frappe.ui.form.on("Target Allocation", {
 business_unit: function(frm) {
 if (frm.doc.business_unit) {{
 "method": "frappe.client.get_list",
 args: {
 doctype: "Employee",
 fieldname: "name",
 filters: {
 "business_unit": frm.doc.business_unit,
  "status": "Active"
callback: function(r) {
 $.each(r.message, function(i, d) {{
 "method": "frappe.client.get",
  args: {
"doctype": "Employee",
callback: function(r) {
if (r.message) {
 var row = frappe.model.add_child(frm.doc, "Target Allocation Employee", "employee_list")
 row.employee_id = r.message.employee;

Hello @PrabavathiDevan thanks for the reply.

I have tried the code, but where to insert the doctype is a bit confusing. Sorry as i am new to Programming. Please can you shed more light on what is to be change.

I am Assuming the “Target Location” is my main doctype which i call “Employee Attendance”
I also Assume the “employee_list” is the child table on the main Doctype which i call “attendance_sheet_employee”.

Please kindly shared more light on the business_unit


“Target Allocation” is my main doctype which you call “Employee Attendance”
and Assume the “employee_list” is the child table on the main Doctype which you call “attendance_sheet_employee” and “Target Allocation Employee” is the child table doctype which you want to replace “attendance_sheet_employee” link table doctype

Hello @PrabavathiDevan, Happy New Year and thanks for the reply. You really solved my question as can be seen in the image below

Please hope you don’t mind if i ask you another question

OK,ask your another question

Thanks @PrabavathiDevan ,

From the image. The Expected Working Days for each employee is 30 Days in a month. I want to be able to deduct Actual Work Days, Approved Leave Days and the remainder as Penalty from the Expected Working Days. And once this change, it should be change dynamically.

For Example;

If for Jan this year, the expected working days is 30, and the Employee works for 20 days, takes leave of 5 days, then the penalty should be 5 days.
And once any of this numbers is change, the system should calculate the new figure. Eg if the leave is change to 6 the penalty should be change to 4 dynamically.

Hello @PrabavathiDevan