Set value In a Child Table Field

If I create a sales invoice and add any item to its child table, then as I edit it, the name of the employee who is creating the sales invoice should come in the blank field of the employee name.

@abhishek_pathak

frappe.ui.form.on("Sales Invoice Item", {
    items_add: function (frm, cdt, cdn) {
       frappe.db.get_value("Employee", {'user_id': frappe.session.user}, ["employee_name"], (r) => {
                frappe.model.set_value(cdt, cdn, "employee_name", r.employee_name);
        });
 }
});
1 Like

Ok Sir Thanks…

@abhishek_pathak Please mark this as solution if it works for you

frappe.ui.form.on("Purchase Order Item", {
    // frm passed as the first parameter
    items_add: function(frm, cdt, cdn){
      if (frm.doc.company == "Touchstone Foundation Ahmedabad"){
          frappe.model.set_value(cdt, cdn, "cost_center", "Ahmedabad - TSF");
        }
    }
})

I am using above code but its not working for me. Can you kindly help?

Hi @V_T_Dasa
Please try the code I hope it’s working

frappe.ui.form.on("Purchase Order Item", {
    items_add: function(frm, cdt, cdn){
        if (frm.doc.company == 'Touchstone Foundation Ahmedabad'){
          cs_center(frm);
        }
    }
})

var cs_center = function(frm){
      frm.set_value("cost_center", "Ahmedabad - TSF")
}

Thank You!

1 Like

Hi @Mohammadali

Thank you, its working now.