Hi, I have created a web form for employees to submit their personal details. For that I have created a New doctype called Employee Update Profile with fields that I want employee to update. Once employee submits web form, hr approves then employee record gets updated. Based on user logged in employee existing details will be fetched into web form.
One of the fields of Web Form is Education child table. I have two separate child tables for Employee and Employee Update Profile doctypes. I am using below client script to fetch employee details. It is fetching and populating existing details except child tables. For child tables it is fetching details (copying from original child table to web form child table) but not visible in web form, what could be the issue?
frappe.web_form.after_load = () => {
console.log("🚀 Web form loaded");
const user = frappe.session.user;
console.log("👤 Logged-in user:", user);
// Set submitted_by field
frappe.web_form.set_value('submitted_by', user);
console.log("✅ Set 'submitted_by' field");
// Step 1: Get Employee ID for the current user
frappe.call({
method: 'frappe.client.get_value',
args: {
doctype: 'Employee',
filters: { user_id: user },
fieldname: 'name'
},
callback: function(response) {
console.log("🔍 Employee lookup response:", response);
if (response.message && response.message.name) {
const employee_id = response.message.name;
console.log("✅ Found Employee ID:", employee_id);
// Set the employee field in the web form
frappe.web_form.set_value('employee', employee_id);
console.log("✅ Set 'employee' field");
// Step 2: Fetch full Employee doc with child tables
frappe.call({
method: 'frappe.client.get',
args: {
doctype: 'Employee',
name: employee_id
},
callback: function(emp_response) {
const employee = emp_response.message;
console.log("📄 Full Employee document:", employee);
// ✅ Debug: Log actual child fields
console.log("🔎 employee.education:", employee.education);
console.log("🔎 employee.external_work_history:", employee.external_work_history);
// Map and set values for regular fields
const fields_to_map = [
'salutation', 'first_name', 'last_name',
'custom_name_as_per_aadhar_card', 'current_accommodation_type',
'custom_houseflat_number', 'custom_address_line_1',
'custom_address_line_2', 'custom_landmark', 'custom_city',
'custom_state', 'custom_country', 'custom_postal_code',
'permanent_accommodation_type', 'custom_flat_number',
'custom_address_line1', 'custom_address_line2',
'custom_landmark_1', 'custom_permanent_city',
'custom_permanent_state', 'custom_country_residence',
'custom_permanent_postal_code', 'custom_marital_status',
'blood_group', 'person_to_be_contacted',
'emergency_phone_number', 'relation',
'custom_aadhar_card_number', 'pan_number',
'passport_number', 'date_of_issue'
];
fields_to_map.forEach(field => {
if (employee[field] !== undefined) {
try {
frappe.web_form.set_value(field, employee[field]);
} catch (e) {
console.log(`Error setting field ${field}:`, e);
}
}
});
// Step 3: Copy Education ➜ Employee Education 2
if (employee.education && employee.education.length > 0) {
const education_copy = employee.education.map(row => ({
school_univ: row.school_univ,
qualification: row.qualification,
specialization: row.specialization,
level: row.level,
class_per: row.class_per,
year_of_passing: row.year_of_passing,
custom_document: row.custom_document
}));
frappe.web_form.set_value('employee_education_2', education_copy);
console.log("✅ Set 'employee_education_2':", education_copy);
} else {
console.log("⚠️ No Education records found in Employee");
}
// Step 4: Copy External Work History ➜ Work History 2
if (employee.external_work_history && employee.external_work_history.length > 0) {
const work_history_copy = employee.external_work_history.map(row => ({
company: row.company,
designation: row.designation,
from_date: row.from_date,
to_date: row.to_date,
branch_address: row.branch_address,
manager_name: row.manager_name,
contact_mobile: row.contact_mobile,
contact_email: row.contact_email,
document: row.document
}));
frappe.web_form.set_value('employee_external_work_history_2', work_history_copy);
console.log("✅ Set 'employee_external_work_history_2':", work_history_copy);
} else {
console.log("⚠️ No External Work History records found in Employee");
}
// Set form status to Draft
frappe.web_form.set_value('form_status', 'Draft');
console.log("✅ Set 'form_status' to Draft");
}
});
} else {
console.warn("❌ No Employee found for user:", user);
}
}
});
};