How to insert multiple docs with child rows with JS?

Hi! My intention is to execute several actions and create docs from a filled custom doc.

Here is my code:

frappe.ui.form.on("Compra de leite Lote", "on_submit", function(frm) {
		let docs = []
		$.each(frm.doc.tabela_dados || [], function(i, v) {
				doctype: "Purchase Receipt",
				set_posting_time: 1,
				posting_date: frm.doc.posting_date,
				posting_time: frm.doc.posting_time,
				supplier: v.produtor,
				items: {
					item_code: (v.qualidade == "Bom" ? "Leche Bueno" : "Leche Acido"),
					qty: v.qtde,
					rate: (v.qualidade == "Bom" ? frm.doc.preco_compra : frm.doc.preço_acido),
					warehouse: "Leite comprado do produtor"
		const funcs = => {{
				method: "frappe.client.insert",
				args: {
					doc: doc // doc object
				callback: function(r) {}

		Promise.all(funcs).then(() => {

It raises an exception at “items” table.
This is the final lines of the exception:

      File "/home/oficina1/erpnext-10.1.42-0/apps/erpnext/htdocs/frappe-bench/apps/erpnext/erpnext/controllers/", line 40, in validate
  File "/home/oficina1/erpnext-10.1.42-0/apps/erpnext/htdocs/frappe-bench/apps/erpnext/erpnext/controllers/", line 70, in set_missing_values
  File "/home/oficina1/erpnext-10.1.42-0/apps/erpnext/htdocs/frappe-bench/apps/erpnext/erpnext/controllers/", line 191, in     set_missing_item_details
    if item.get("item_code"):
AttributeError: 'unicode' object has no attribute 'get'

I’m kind of newbie on this… I presume i’m doing something wrong to insert rows on my doc, no?

Thanks in advance!

1 Like

Sorry, my code is wrong.
Forgot to put brackets around item, so it c
ould be interpreted as dict instead of strings.