Hey everyone,
I’m trying to fetch a custom field from Purchase Invoice to the Payment Entry Reference table. I need this info to pull when a user creates a Payment Entry from the Make>Payment Entry menu. I have not found a good way to do this. Can anyone be of assistance?
@max_morais_dmm You posted the following:
frappe.ui.form.on('Lead Contact', 'form_render', function(frm, cdt, cdn){
locals[cdt][cdn].company = frm.doc.company;
});
Is there any way to pull from the previous document instead of the parent document?
Edit: The following do not work:
frappe.ui.form.on('Payment Entry Reference', {
form_render: function(frm, cdt, cdn){
frm.add_fetch("reference_name", "bill_no", "bill_no");
frm.refresh_field("reference_name");
},
onload_post_render: function(frm, cdt, cdn){
frm.add_fetch("reference_name", "bill_no", "bill_no");
frm.refresh_field("reference_name");
}
});
It seems that this doesn’t work on child tables.
@cpurbaugh first thing:
frm.add_fetch
only works if added in the onload
method of parent doctype, don´t matter if the field is in the parent or not.
So, the right way to do that is:
frappe.ui.form.on("Payment Entry", "onload", function(frm){
frm.add_fetch("reference_name", "bill_no", "bill_no");
});
Alternativelly, you can do that on validate, something like:
frappe.ui.form.on("Payment Entry", "validate", function(frm){
var dt, references = (frm.doc.references || []).map(function(row){
if (dt === undefined) dt = row.reference;
return row.reference_name;
});
frappe.call({
'async': false,
'method': 'frappe.client.get_list',
'args': {
'doctype': dt,
'fields': ['name', 'bill_no'],
'filters': {'name': ['in', references]}
},
callback: function(res){
(res.message || []).forEach(function(row){
var ref = frappe.utils.filter_dict(frm.doc.references, {'reference_name': row.name})[0];
frappe.model.set_value(ref.doctype, ref.name, "bill_no", row.bill_no);
})
}
})
});
1 Like