我想根据另一个doctype中的记录动态添加子表。
答案 0 :(得分:0)
@Sajid liaz
您可以使用append方法在子表中添加行
例如
let errors = [];
let radiobutton = form.getAnswerText("sIsPersonLongTermNeeds");
if (radiobutton == "sIsPersonLongTermNeedsNo" ||
radiobutton == "sIsPersonLongTermNeedsUnknown"
) {
window.confirm("text");
}
其中doc = frappe.get_doc('Sales Order', 'SO-00002')
doc.append('items', {
'company': 'company_name',
'item_code': 'item_code',
'item_name': 'item_name',
'field': 'field_value'
})
doc.save()
是子表的字段名。
答案 1 :(得分:0)
有几种方法可以在父文档中添加子对象:
`
import frappe
parent = frappe.get_doc('Sales Order', 'SO-00002')
child = frappe.new_doc("Sales Order Item")
child.update({
'company': 'company_name',
'item_code': 'item_code',
'item_name': 'item_name',
'field': 'field_value'
'parent': parent.name,
'parenttype': 'Sales Order',
'parentfield': 'items'
})
parent.items.append(child)
import frappe
parent = frappe.get_doc('Sales Order', 'SO-00002')
child = frappe._dict({
'company': 'company_name',
'item_code': 'item_code',
'item_name': 'item_name',
'field': 'field_value'
})
parent.items.append(child)
`
答案 2 :(得分:0)
这是可能的,因为DocType在Frappe Framework中被视为数据。 但是,必须将在运行时添加的动态字段添加为“自定义字段”。
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
create_custom_field('Task' {
"fieldname": 'values',
"label": 'Values',
"fieldtype": 'Table',
"options": 'Child Table'
})