I have doctype A contain link to doctype B.
I custom a button to generate doctype B and want to set A.b = target_doc.
Thank everybody
client side
if ((frm.doc.salary_structure) && (frm.doc.docstatus === 1) && frm.doc.employee) {
frm.add_custom_button(__('Salary structure Assignment'), function () {
frappe.model.open_mapped_doc({
method: "erpnext.hr.doctype.employee_onboarding.employee_onboarding.make_salary_structure_assignment",
frm: frm,
})
}, __("Make"));
sever side
@frappe.whitelist()
def make_salary_structure_assignment(source_name, target_doc=None):
doc = frappe.get_doc("Employee Onboarding", source_name)
target_doc = get_mapped_doc("Employee Onboarding", source_name, {
"Employee Onboarding": {
"doctype": "Salary Structure Assignment",
"field_map": {
"base": "base",
"from_date": "from_date",
"employee": "employee"
}}
}, target_doc)
doc.salary_structure_assignment = target_doc.name
return target_doc