How to set value in a child table HTML field?

How to set value in a child table HTML field?
frappe.ui.form.on(“Item”, {
refresh: function (frm) {
console.log(‘Processing participant and event data’);

    // Check if both tables have data
    if (frm.doc.custom_participants_table.length > 0 && frm.doc.custom_event_dates.length > 0) {
        let tableHTML = `
            <table style="border-collapse: collapse; width: 100%; border: 1px solid #ddd;">
                <thead>
                    <tr>
                        <th style="border: 1px solid #ddd; padding: 8px;">Participant ID</th>
                        <th style="border: 1px solid #ddd; padding: 8px;">Event Number</th>
                    </tr>
                </thead>
                <tbody>
        `;

        // Iterate over custom_participants_table
        frm.doc.custom_participants_table.forEach(function(participant) {
            frm.doc.custom_event_dates.forEach(function(event) {
                tableHTML += `
                    <tr>
                        <td style="border: 1px solid #ddd; padding: 8px;">${participant.participant_id}</td>
                        <td style="border: 1px solid #ddd; padding: 8px;">${event.event_number}</td>
                    </tr>
                `;

                // Ensure participant_list exists before adding
                if (frm.doc.custom_event_dates && frm.doc.custom_event_dates.participant_list) {
                    frm.add_child('custom_event_dates.participant_list', {
                        participant_id: participant.participant_id,
                        event_number: event.event_number
                    });
                }
            });
        });

        tableHTML += `</tbody></table>`;

        // Set the HTML table in the custom field of the event_dates table
        
    }
}

});

Reference: Add a Child Table Doctype in a anoter Child Table Doctype? - #4 by avc

1 Like