Perform calculation and fill the adjacent column in the already filled child table

Hi Team,

I am trying to push the value of the one child table named “child_table1” to another child table “child_table2” based on the value in the “child table1” below child table1 in the same doctype

In “child table2” only few columns from childtable1 with additional details need to inserted.

Please advice.

Thanks all for your support

@balramrjpm check this Fetch Child table values to another child table

But one doctype to another, or in same doctype?

Same Doctype…

that for, you have to apply client or server script.

please check the syntax of client script.

frappe.ui.form.on('Parent DocType', {
    before_save: function(frm) {
        frm.clear_table('child_table2');

        frm.doc.child_table1.forEach(function(row) {
            if (row.some_field == "some_value") {
                let new_row = frm.add_child('child_table2');
                new_row.field_name_in_child_table2 = row.field_name_in_child_table1;
            }
        });

        frm.refresh_field('child_table2');
    }
});

@NCP I have the access for the client script but I dont have the access server script apologies for the confusion will try and let you know thks

Is it possible to make the child table field read only mode once insert for the particular columns based on the role pls let me know

You can use the client script so check the format, that i provided.

Check this reference: How to make child table field read only as per child table field condition whenever load - #4 by Mohammadali

pls advise as I am not sure what need to pass as the argument in below code

“Test Child” is the parent doctype or child?
“child_name” which is the parent doctype child table field name or child doc type name itself?

frappe.ui.form.on('Test Child', {
    status: function(frm, cdt, cdn) {
        let child_doc = locals[cdt][cdn];
        if (child_doc.status == "Pending") {
            frm.fields_dict['child_name'].grid.grid_rows_by_docname[cdn].toggle_editable('field_name', false);
        } else {
            frm.fields_dict['child_name'].grid.grid_rows_by_docname[cdn].toggle_editable('field_name', true);
        }
    }
});

Child doctype name

parent doctype child table field name

Is it possible to toggle read only based on the user role?

check frappe.user.has_role condition

I tried as you mentioned but didnt work I shared the whole code of the child table for your reference

frappe.ui.form.on("Stationery Item Information", {
  item_list_add(frm, cdt, cdn) {
    
    // adding values from the parent to child table 
    console.log(frm.doc.workflow_state);
    let row = locals[cdt][cdn];
    row.category = frm.doc.category;
    row.sub_category = frm.doc.sub_category;
    row.item_name = frm.doc.item_name;
    row.unit = frm.doc.unit;
    row.max_qty = frm.doc.max_qty;
    row.stock_qty = frm.doc.stock_qty;
    row.required_qty = frm.doc.required_qty;
    row.approved_qty = frm.doc.approved_qty;
    frm.set_value("required_qty", null);
    // frm.set_df_property('item_list', 'read_only', 1, frm.docname, 'approved_qty', row.name);
    frm.refresh_field("item_list");
    // setreadonly(frm,cdt,cdn);
  },
  
  // Change the field property
  required_qty:function(frm, cdt, cdn) {
        let child_doc = locals[cdt][cdn];
        if (frm.doc.workflow_state == "Draft") {
            frm.fields_dict['item_list'].grid.grid_rows_by_docname[cdn].toggle_editable('approved_qty', false);
        } else {
            frm.fields_dict['item_list'].grid.grid_rows_by_docname[cdn].toggle_editable('approved_qty', true);
        }
    },

    approved_qty: function(frm, cdt, cdn) {
        calculateBalanceQty(frm, cdt, cdn);
    }
});

function calculateBalanceQty(frm, cdt, cdn) {
    var d = locals[cdt][cdn];
    var balanceQty = d.required_qty - d.approved_qty;
    if (balanceQty<0){
        frappe.msgprint("Enter the approved qty not more than required qty");
        frappe.model.set_value(cdt, cdn, 'approved_qty', null);
        frappe.model.set_value(cdt, cdn, 'balance_qty', null);
        frm.refresh_field('approved_qty');
        frm.refresh_field('balance_qty');
    } else {
    frappe.model.set_value(cdt, cdn, 'balance_qty', balanceQty);
    // Optionally refresh the field if necessary
    frm.refresh_field('balance_qty');
    }
}

I have given many hints, now test it yourself. so debug it and check it one by one.

@NCP Sure bro thks will perform the debugging and let u know further