how to add this script to table can anyone wright a code for me?
Hi @Qasrawii986,
Please check its post.
// Syntax
frappe.ui.form.on("Child Table Name", {
field_name_for_trigger_to_value_calculate: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, 'child_table_total_value', (d.child_table_value1 * d.child_table_value2));
// frm.refresh_field('child_table_name');
}
});
I hope this helps.
Thank You!
frappe.ui.form.on(“Item used in Mantineans”, {
rate: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, ‘amount’, (d.rate * d.qty));
}
});
//Syntax
frappe.ui.form.on(“Item used in Mantineans”, {
amount: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, ‘amount’, (d.rate * d.qty));
frm.refresh_field(‘Item used in Mantineans’);
}
});
this code work for me but it take the default qty , i need it to take the qty i wrote it not the default
ــــــــــــــــــــــــــــــــــــــــــــــ
ــــــــــــــــــــــــــــــــــــــــــــــــــــــ
this code solve my problem
frappe.ui.form.on(“Item used in Mantineans”, {
rate: function(frm, cdt, cdn) {
calculateAmount(frm, cdt, cdn);
},
qty: function(frm, cdt, cdn) {
calculateAmount(frm, cdt, cdn);
}
});
function calculateAmount(frm, cdt, cdn) {
var doc = locals[cdt][cdn];
var rate = doc.rate;
var qty = doc.qty;
if (rate && qty) {
var amount = rate * qty;
frappe.model.set_value(cdt, cdn, 'amount', amount);
refresh_field('amount', cdn, cdt);
} else {
frappe.model.set_value(cdt, cdn, 'amount', 0);
refresh_field('amount', cdn, cdt);
}
}