Child table fill data

Hi all,

How can i fill data from parent to child automatiqlly in javascript

I have used these lines but it is not working

frappe.ui.form.on(“Dependent”, {
onload: function (frm) {
frm.set_value(“customer_number”, “4444”);
}

@MaysaaSafadi,

for child table field use the frappe.model.set_value method instead

e.g. frappe.model.set_value(cdt, cdn, fieldname, value)

Thanks,
Makarand

Thanks @makarand_b

but the problem here that it is not enter the load function and i want to fill the child table data when adding new row in it

frappe.ui.form.on(“Dependent”, {
onload: function (frm) {

}

Try

frappe.ui.form.on("Dependent", {
validate: function (frm) {

}

thanx @JoEz

I try it, and still not working

Where are you writing the script? Share all your code

@JoEz

I have Customer which is the parent and Dependent is the child table

here code in Customer.js>>

frappe.ui.form.on(‘Customer’, {
onload: function(frm) {
}
});

frappe.ui.form.on(“Dependent”, {
validate: function (frm) {
console.log(‘mnmnmn’);
frm.set_value(“customer_number”, “4444”);
}
});

you should put the Dependent function inside Customer custom script, use @makarand_b suggestion and use:

frappe.model.set_value(cdt, cdn, fieldname, value)

so go to Custom Script, open it and select Customer and add:

frappe.ui.form.on("Dependent", "validate", function (cdt, cdn) {
     frappe.model.set_value(cdt, cdn, fieldname, value);
});

@JoEz

I tried it but not working :frowning2:

Just i want to change a field value in the child table on load it

When u want to change the value? Share an animation on what u want to do …

@JoEz

Thank u,
I solved it, here the solution:

frappe.ui.form.on("Dependent", "form_render", function(frm, cdt, cdn) {
     frappe.model.set_value(cdt, cdn, 'customer_number', cur_frm.doc.customer_number);
});
1 Like