How to populate this table


I want to populate the child table with the item name which is selected in the top item table

Hello @amal_31845 , please try this code
frappe.ui.form.on(‘Item’, { //top child table doctype
refresh(frm) {
},
item_code(frm, cdt, cdn) {
let current_row = locals[cdt][cdn];

        let item_series = frm.add_child('item_series'); //bottom child table field name
        item_series.item_series = current_row.item_name;
        item_series.series_no = current_row.series_no
       
        frm.refresh_field('item_series');
   }

})

frappe.ui.form.on('Sales Order', {
    custom_test: function(frm, cdt, cdn) {
     
            var row = locals[cdt][cdn];
            console.log(row);
            if (row.item_name) {
                frappe.ui.form.on('items', {//top child
                    refresh: function(frm) {
                    },
                    item_code: function(frm, cdt, cdn) {
                        let current_row = locals[cdt][cdn];
                        let item_series = frm.add_child('custom_item_serial'); // bottom child table field name
                        item_series.item_series = current_row.item_name;
                        frm.refresh_field('custom_item_serial');
                    }
                });
                cur_frm.refresh_field("custom_item_serial");
        }
    }
});

items - is the field name of the top child
item_name - is the field name in items in child table
custom_item_serial - is the field name of the bottom child
item_series - is the field name in custom_item_serial child table
i want to add item series values item_name

frappe.ui.form.on('items', {//top child
                    refresh: function(frm) {
                    },
                    item_code: function(frm, cdt, cdn) {
                        let current_row = locals[cdt][cdn];
                        let item_series = frm.add_child('custom_item_serial'); // bottom child table field name
                        item_series.item_series = current_row.item_name;
                        frm.refresh_field('custom_item_serial');
                    }
       })

On change of item_code in the top child table, add a row in the bottom child table, and set item_name in item_series field.

1 Like
frappe.ui.form.on('Sales Order', {
    on_save: function(frm, cdt, cdn) {
        var row = locals[cdt][cdn];
        console.log(row);
        if (row.item_name) {
            frappe.ui.form.on('items', {
                refresh: function(frm) {
                    let item_series = frm.add_child('custom_item_serial'); // bottom child table field name
                    item_series.item_series = row.item_name;
                    frm.refresh_field('custom_item_serial');
                }
            });
            cur_frm.refresh_field("custom_item_serial");
        }
    }
});

i want ,like when the customer click on save iwant to check the custom_test have particalular value example

  • if custom_test ==1 then item series should have the yhe items which is added on the items table
    (example - if items table have 2 items the twotwo items name should add in item_series as two row)

  • if custom_test == 0 no change on save
    @Krishn

frappe.ui.form.on('Sales Order', {
    before_save: function(frm, cdt, cdn) {
        if (custom_test == 1) {
            frm.doc.items.forEach(function(row) { 
                let item_series = frm.add_child('custom_item_serial'); // bottom child table field name
                item_series.item_series = row.item_name;
                frm.refresh_field('custom_item_serial');
            });
        }
    }
});

Please try this


if (frm.doc.custom_test == 1) {

1 Like
frappe.ui.form.on('Sales Order', {
    custom_test: function(frm, cdt, cdn) {
        if (frm.doc.custom_test == 1) {
            frm.doc.items.forEach(function(row) { 
                let item_series = frm.add_child('custom_item_serial'); // bottom child table field name
                item_series.item_series = row.item_name;
                frm.refresh_field('custom_item_serial');
            });
        }
    }
});

can i change this to before save to onchange of custom_test

yes, you can

1 Like


can i fetch the items from the top table when it changes
when each items changes it will added to the item series

frappe.ui.form.on('Sales Order', {
    items: function(frm, cdt, cdn) {
        if (frm.doc.custom_test == 1) {
            frm.doc.items.forEach(function(row) { 
                let item_series = frm.add_child('custom_item_serial'); // bottom child table field name
                item_series.item_series = row.item_name;
                frm.refresh_field('custom_item_serial');
            });
        }
    }
});


this is the item_code in the child table

frappe.ui.form.on(‘Sales Order Item’, { //top child table doctype
refresh(frm) {
},
item_code(frm, cdt, cdn) {
let current_row = locals[cdt][cdn];

        let item_series = frm.add_child('item_series'); //bottom child table field name
        item_series.series_no = current_row.item_name
       
        frm.refresh_field('item_series');
   }

})

sorry brother for confusing you.

frappe.ui.form.on('Sales Order', {
    when open: function(frm, cdt, cdn) {
        if (frm.doc.custom_test == "Production") {
            frm.doc.items.forEach(function(row) { 
                let item_series = frm.add_child('custom_item_serial'); // bottom child table field name
                item_series.item_series = row.item_name;
                frm.refresh_field('custom_item_serial');
            });
        }
    }
});

i explain my need @Krishn

  • When the workflow is at Production approval stage imake the custom test as Production

  • So i want whenever the documents open i want to verify the custom_test is production then i need to populate the values
    so how can i make

When the docuent get open