I used the below script to set fields automatically while creating new doctype from a link field, it is working fine! Now I need for the table data to set for new doctype from previous doctype using the same approach, please help…
Try following code or on the same line, or may get some hint (as such it may not work, you need to read it understand and then adapt):
frappe.ui.form.on('Opportunity', {
refresh(frm) {
// Fetch custom_opportunity_item or initialize as an empty array
let items = frm.doc.custom_opportunity_item || [];
// Set route options for the new doc
frm.get_docfield('custom_select_required_site_visit').get_route_options_for_new_doc = function (field) {
// Create an array to hold table data (child rows)
let custom_opportunity_items = [];
// Loop through the items in the child table and prepare data
items.forEach(item => {
custom_opportunity_items.push({
item_code: item.item_code,
description: item.description,
qty: item.qty,
rate: item.rate
// Add more fields if needed from the child table
});
});
return {
"company": frm.doc.company,
"customer": frm.doc.party_name,
"custom_opportunity_item": custom_opportunity_items // Pass child table data
};
};
}
});