Total amount not shown when using custom sales invoice item table, HELP!

I created a custom sales invoice item table to include fields that I want to display in my sales invoice. My problem is, after creating the custom sales invoice table, it does not calculate the total amount (qty*rate).

I am trying to use this script that I saw on the forums:

frappe.ui.form.on(‘Sales invoice item 3’, {
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);
},
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);
}
})

Where should I input this code?