Automatically fill Child Table rows

Hi,
Can someone help me… I have to automatically populate list of child companies in a child table row by row when a parent company is selected in the same child table. I have done halfway but the all the company is getting selected in the same row itself. I want it row after row
Below is my script

frappe.ui.form.on("Item Default","company",function(frm,cdt,cdn){
    var d=locals[cdt][cdn];
    var c=[];
    if(d.company=="Company-01"){                   //Check if it is the parent company
        console.log(d.company);
        var comp=frappe.db.get_list('Company',{
        fields:['company_name'],   
        filters:{
            parent_company:'Company-01'           // Get all the child company
        }
        }).then(records=>{
            console.log(records);
            var d=records.length>0?records:[]
            for(var i=0;i<d.length;i++){
                var ff=d[i].company_name;
                c.push(ff)
        }
    frappe.model.set_value(cdt,cdn,"company",c)
    })
    }
});

Thanks…In advance

Check this out: Child Table Link Field Population - #76 by Vesper_Solutions

At the very end of the feed, you’ll see a general template I’ve cited to populate child tables on every criteria possible

Thank you for the response…
I tried…still it isnt working
can you tell me how to do it?

Cite your form structure and all related fields

Thank you for your time…let me explain my requirement ,In the Item Doctype, there is a child table “Item Default”, when i select my parent company “Company-01” in the first row…i need my rest of the child companies “company-02,company-03” automatically fetch in each of the rows

Thank you for your support…I have solved it