Error filling child table

hi everyone, I am trying from a custom doctype, create and fill out a delivery note, at the time of saving the custom form, after reading this forum for a long time I made this custom script, but I get an error in the console, I would appreciate someone “light up”, thank you all.

var doc = frappe.model.get_new_doc(‘Delivery Note’);
doc.title= “Delivery Note”;
doc.customer=frm.doc.customer; “Company Name.”;

    $.each(frm.doc.items, function(index, row){
         var childTable = cur_frm.add_child(doc.items);
        childTable.item_code= row.item_code;
        childTable.item_name= row.item_name;
        childTable.qty= row.qty;
        childTable.uom= row.uom;
        chilTable.conversion_factor= row.conversion_factor;
        childTable.set_warehouse= row.set_warehouse;
        childTable.description= row.description;

and the error in console

TypeError: Cannot read property ‘options’ of undefined
at frappe.ui.form.Form.add_child (form.min.js?ver=1591244483.0:1)
at Object.eval (eval at setup (form.min.js?ver=1591244483.0:1), :37:38)
at Function.each (jquery.min.js:2)
at before_save (eval at setup (form.min.js?ver=1591244483.0:1), :28:11)
at a (form.min.js?ver=1591244483.0:1)
at form.min.js?ver=1591244483.0:1
c @ form.min.js?ver=1591244483.0:1
Promise.catch (async)
validate_and_save @ form.min.js?ver=1591244483.0:1
(anonymous) @ form.min.js?ver=1591244483.0:1
setTimeout (async)
(anonymous) @ form.min.js?ver=1591244483.0:1
save @ form.min.js?ver=1591244483.0:1
Save @ form.min.js?ver=1591244483.0:1
(anonymous) @ desk.min.js?ver=1591244483.0:1
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3