I added a custom link field in the Sales Order Items table and added same field (with same name) in the Sales Invoice Items table. However, when I create a Sales Invoice from Sales Order, the field doesn’t get mapped! I thought this should happen automatically?
How can I achieve this mapping via custom script? I’ve tried some of the suggestions I found on the forum but they don’t seem to work
have you tried using a custom trigger, say like a custom button to trigger the code and see if the code actually works as intended? from seeing the code, it should have worked, maybe its not getting triggered the right way,
& i think on line 3, its with_doctype , not just with_doc, and frm,doc.onload, not needed i think,
similar fetching items from one table to sales invoice , using with_doctype, and no trigger there, this can be defenitely optimised and cut short to fit your needs
relevenat parts of the code is below
var get_doc = function(mydocname){
var sinv;
return new Promise(function(resolve) {
frappe.call({
"method": "frappe.client.get",
"args": {
"doctype": "My custom Doc",
"name": mydocname
},
"callback": function(response) {
sinv = response.message.items;
resolve(sinv);
}
});
});
}
cur_frm.add_custom_button(__(button_name_var), function(frm) {
get_doc(cur_frm.docname).then(
function(result) {
frappe.model.with_doctype('Sales Invoice', function() {
var si = frappe.model.get_new_doc('Sales Invoice');
si.customer= cur_frm.doc.customer;
result.forEach(function(item) {
var si_item = frappe.model.add_child(si, 'items');
si_item.item_code = item.item_code;
});
frappe.set_route('Form', 'Sales Invoice', si.name);
});
}
);
});
Interestingly, when I try creating other fields with the same name on both docs, they get mapped! The only difference that comes to mind right now is that the field not getting populated is an accounting dimension so it was automatically created… I’m not sure if this could have anything to do with the issue