Set values into child table

@NAGENDRA_KOMMIREDDI

Add console.log() and debug what parameters are you sending as well as what response you get?

Can you explain what are trying to achieve?

where is detials field. If this is a field from your parent form then you have to iterate child table entries to set values in every row of the table.

e.g.

frappe.ui.form.on("Registration",{
	detials: function(frm) {
		$.each(frm.doc.tablefieldname || [], function(i, v) {
			frappe.model.set_value(v.doctype, v.name, "email", "xyz@gmail.com")
		})
	}
})
1 Like

details is the name of the child table …


i want to set the values for the fields in child table
and the child table is and
sangram ji thank you for your reply

you mentioned detials in your code correct it and try again.

sry i can’t understood what you are saying can you please tell me with the help of a code …
thank you

Explain in details what are you trying? On which event you want to fill the field in a table?

After clicking the button at the top i want to fill the table
is there any function like that the cur_frm.set_value

So, after click on verify button, you want to fill table fields.

try this

frappe.ui.form.on("Registration",{
	verify: function(frm) {
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "User",
				filters: {"email":user}    //user is current user here
			},
			callback: function(r) {
				$.each(frm.doc.details || [], function(i, v) {
					frappe.model.set_value(v.doctype, v.name, "name1", r.message.full_name)
					frappe.model.set_value(v.doctype, v.name, "email", r.message.email)
					frappe.model.set_value(v.doctype, v.name, "phone", r.message.phone)
				})
				frm.refresh_field('details');
			}
		})
	}
})

I tried but i am not getting the values in the tables …Thank you …

What is Current_User?
Add console.log in callback and check response

e.g

callback: function(r) {
				console.log("response",r.message)

and check this in your browser console

but i am getting the field values for the above three functions…

Thanks i think now i got the solution…I will not forget your help…thank you so much…

sorry for troubling you again …but i want to modify it little bit the code i just write …
i want to store the different users in the same doctype but because of this code it just duplicating all the values whenever the verify button is clicked


Thank you for your reply once again

How you solve this problem… pls help me i’m also get this problem

what is your problem exactly ?
he is using a for each function which iterates each row so he will keep getting the same entry in every row. if thats was your question.

Hello, I have had the same error for months and today I have solved sending the array.

cur_frm.set_value(“field_value”, data.message);

Complete code:

frappe.call({
	method: "frappe.client.get_list",
	args: {
		doctype: "Doctype table childs",
		fields: ["*"],
		filters: [["parent", "=", "name register parent"],],
		parent: "Employee"
	},
	callback: function (data) {
		if(data && data.message) {
			cur_frm.set_value("education", data.message);
		}
	}
});
4 Likes

Hi ,
How you solve this problem… pls help me i’m also get this problem

Hi @smehata,
Check this out…

can you show your frappe.client.get method?

frappe.ui.form.on("Registration",{
	verify: function(frm) {
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "User",
				filters: {"email":user}    //user is current user here
			},
			callback: function(r) {
				cur_frm.clear_table("details");
				for (var i =0; i < r.message.length; i++){
				frappe.model.add_child(cur_frm.doc, "Regs Details", "details");
				}
				$.each(frm.doc.details || [], function(i, v) {
					frappe.model.set_value(v.doctype, v.name, "name1", r.message[i].full_name)
					frappe.model.set_value(v.doctype, v.name, "email", r.message[i].email)
					frappe.model.set_value(v.doctype, v.name, "phone", r.message[i].phone)
				})
				frm.refresh_field('details');
			}
		})
	}
})

If you need to update a field in Child table simple AJAX call
frappe.call({
“method”: “frappe.client.set_value”,
“args”: {
“doctype”: child_table_name,
“name”: name_of_row,
“fieldname”: {
“field_name1”:“value1”,
“field_name2”:"value2
}
}
})

1 Like