Good day guys. how can i create custom to multiply Qty * price and populate amount field and also sum the amount to get total_amount? below is the image for UI

It did not work sir . did i need to add to the child table

this my code;

frappe.ui.form.on(‘Labour’, {

refresh(frm) {

qty:function(frm,cdt,cdn){

var d = locals[cdt][cdn];

var amount = (flt(d.qty) * flt(d.rate)) ;

frappe.model.set_value(cdt, cdn, “amount”, amount);

}

```
rate:function(frm,cdt,cdn){
var d = locals[cdt][cdn];
var amount = (flt(d.qty) * flt(d.rate)) ;
frappe.model.set_value(cdt, cdn, “amount”, amount);
}
amount:function(frm,cdt,cdn){
var d = locals[cdt][cdn];
var amount = (flt(d.qty) * flt(d.rate)) ;
frappe.model.set_value(cdt, cdn, “amount”, amount);
}
}
});
```

My code will not work. it is for field.

your request is for grid calculation.

Try below link.

this one works for to obtain amount.

frappe.ui.form.on(‘Labour’, {

“qty”: function(frm, cdt, cdn) {

let gridRow = frm.open_grid_row();

if (!gridRow) {

gridRow = frm.get_field(‘concreting’).grid.get_row(cdn);

}

calAmount(gridRow);

},

“rate”: function(frm, cdt, cdn) {

let gridRow = frm.open_grid_row();

if (!gridRow) {

gridRow = frm.get_field(‘concreting’).grid.get_row(cdn);

}

calAmount(gridRow);

},

});

function calAmount(gridRow) {

let qty = gridRow.on_grid_fields_dict.qty.value;

let rate = gridRow.on_grid_fields_dict.rate.value;

let amount = qty * rate;

frappe.model.set_value(

gridRow.doc.doctype,

gridRow.doc.name,

‘amount’,

amount

);

}

How would i sum the total Amount? i.e Total Amount = amount1 + amount2 + amount3.

Total amount field name is on the main form. the amount1, 2, 3… is coming from the child table.