Fetch data to child table Server/Custom Script

Hi,
I have a child table (Delivered Services)with three fields:

  1. Invoice (link field - links to Invoice doctype)
  2. Amount (currency field)
  3. Hours (float field)

The Invoice field has two fields:

  1. total_amount (currency field)
  2. total_hours (float field)

Whenever i select an invoice for a table row, I want to fetch the amount and hours field data from the selected Invoice. i.e hours field in table should have the total_hours value of selected invoice and amount field in table should have the total_amount value of selected invoice. Each row will have its respective selected Invoice.

I have written a custom script on the Parent Doctype (Plan) for the child doctype (Delivered Services). Now Invoice is not the parent for delivered services, it is a simple doctype, the parent is Plan. However my app does not fetch the values. Any help is appreciated, my code is as follows:

frappe.ui.form.on(‘Delivered Services’, {
refresh(frm) {
cur_frm.add_fetch(‘invoice’,‘invoice.total_hours’,‘hours’)
}
})

where:
1.invoice is the link field in the child table (linking to invoice doctype).
2. invoice.total_hours is the float field in the invoice doctype.
3. hours is the float field in the child doctype.