Fetch data from linked table linked to a child table

I have one doctype with a table field linked to a child doctype that have a link to a doctype that have a link to another doctype:

Product ( documents: table[Product_Documents])
*Product_Documents(document:link[Document], doctype_virtual:data) *child
Document(dty_doc:link[Document type], name_doc:data)
Document type (name_dty:data)

I need a script that gets the value from name_dty field and set the value to doctype_virtual field.
How can I achieve it?

I tried this but it’s not working:
frappe.ui.form.on(‘Product_Documents’, {
refresh(frm) {
cur_frm.add_fetch(“dty_doc”, “name_dty”, “doc_type_virtual”);
}
})

Please check it.

In case someone have the same problem.
I’ve created a script for Product doctype

frappe.ui.form.on('Product_Documents', {
    document: function(frm, cdt, cdn) {
        let row = locals[cdt][cdn];
        if (row.document) {
            frappe.db.get_value('Document', row.document, 'dty_doc', (value) => {
                if (value) {
                    frappe.db.get_value('Document type', value.dty_doc, 'name_dty', (dty_value) => {
                        if (dty_value) {
                            frappe.model.set_value(cdt, cdn, 'doc_type_virtual', dty_value.name_dty);
                        }
                    });
                }
            });
        }
        
    }
});