I am using a custom script to pull item codes from another DocType. This is supposed to work as some sort of a quotation template for regulary used items. It works perfectly fine with just one major exception. Once I have added the item codes using the “Get Items From”-Button the fetch fields are not being refreshed, leading to a table with item codes but no rate or amount displayed. I then have to click in the item_code field and basically select them again. Then all information is pulled as desired.
Any thoughts on how to refresh the table thoroughly?
The code I am using:
// The fetch-from fields
var fields = [
“item_code”,
“qty”,
“rate”,
“amount”];
frappe.ui.form.on(‘Quotation’, {
refresh(frm) {
frm.add_custom_button(‘Angebotsvorlage’, function () { frm.trigger(‘get_items’) }, __(“Get Items From”));
},
get_items(frm){
start_dialog(frm);
}
});
function start_dialog(frm) {
let dialog = new frappe.ui.form.MultiSelectDialog({
// Read carefully and adjust parameters
doctype: "Angebotsvorlage", // Doctype we want to pick up
target: frm,
setters: {
// MultiDialog Filterfields
// customer: frm.doc.customer,
},
date_field: "creation", // "modified", "creation", ...
get_query() {
// MultiDialog Listfilter
return {
filters: { }
};
},
action(selections) {
for(var n = 0; n < selections.length; n++){
var name = selections[n];
frappe.db.get_doc("Angebotsvorlage", name) // Again, the Doctype we want to pick up
.then(doc => {
// Remove the first empty element of the table
if(!('item_code' in frm.get_field("items").grid.grid_rows[0].doc)){
frm.get_field("items").grid.grid_rows[0].remove();
}
// Run through all items of the template quotation
for(var n = 0; n < doc.angebotsvorlage_item.length; n++){
// Declare variables and add table row
var item=doc.angebotsvorlage_item[n];
var row=frm.add_child("items"); // Zeile anlegen
frm.refresh_fields("items"); // Refresh Tabelle
// Copy-Paste Operation
for(var m = 0; m < fields.length; m++){
frm.get_field("items").grid.grid_rows[n+1].doc[fields[m]] = item[fields[m]];
frm.get_field("items").grid.grid_rows[n+1].refresh_field(fields[m]);
}
frm.refresh_fields("items"); // Refresh Tabelle
}
});
}
}
});
}