frappe.ui.form.on('<< Child Table DocType Name >>', {
<< Field name on child table #1 >>: function(frm, cdt, cdn) {
let gridRow = frm.open_grid_row();
if (!gridRow) {
gridRow = frm.get_field('<< Field name of child table on main form >>').grid.get_row(cdn);
}
calAmount(gridRow);
},
<< Field name on child table #2 >>: function(frm, cdt, cdn) {
let gridRow = frm.open_grid_row();
if (!gridRow) {
gridRow = frm.get_field('<< Field name of child table on main form >>').grid.get_row(cdn);
}
calAmount(gridRow);
},
});
function calAmount(gridRow) {
let qty = gridRow.on_grid_fields_dict.<< Field name on child table #1 >>.value;
let rate = gridRow.on_grid_fields_dict.<< Field name on child table #2 >>.value;
let amount = qty * rate;
frappe.model.set_value(
gridRow.doc.doctype,
gridRow.doc.name,
'<< Field name on child table #3 >>',
amount
);
}
As far as I could understand, you want to make changes a cell of the grid based on the changes you do in other cell of the table. For the that you have to first listen to the change being done in a particular cell. The code which you have pasted should work. Check the name of fields and put js debug points to check whether it reaches there… I will put a generic code here, may be reviewing it may help you to identify your problems. Generally the syntax should be as follows:
frappe.ui.form.on("<Child Table Name>", "<Fieldname>", function(frm, cdt, cdn) {
var item = locals[cdt][cdn]; // Fetching field from child table type and name
var val = 1000 // Some value here
item.result_field = val; // you may require to refresh
});
To refresh try cur_frm.refresh() or cur_frm.dirty(); and see if it changes the table.
I’m getting the this custom script error "
SyntaxError: In strict mode code, functions can only be declared at top level or inside a block
"
below is edited code
frappe.ui.form.on(‘Labour’, {
refresh(frm) {
qty :function(frm, cdt, cdn) {
let gridRow = frm.open_grid_row();
if(!gridRow){
gridRow = frm.grid_field(‘concreting’).grid.get_row(cdn);
}
calAmount (gridRow);
}