Child table javascript update field

how i can update a field (i suppose in javascript) of a child table in “real time” as occurs in “Amount” in purchase order item?


Can you explain the full use-case.

Just to share some experience. Assuming if you want to update the Price List Rate field in a Purchase Invoice Item child table. You could try the following:

cur_frm.get_field("items").grid.grid_rows[0].doc.price_list_rate = 1

Just replace row[0] with the row number in your child table you want to update.


I have two fields in child table, “Price” and “Quantity”. When one of two is modified a third field “Amount” must change with the result of multiplication.

thanks bohlian,
what is the event to be used when i modify another field of child table?

1 Like
frappe.ui.form.on("Purchase Invoice Item", "price_list_rate", function(frm, doctype, name) {

Put this in a custom script for “Purchase Invoice”. This will listen to changes on the price_list_rate child table field.



I am trying to do something similar in the Purchase Recept doctype but I can’t make it work.
I did many tries including that:

frappe.ui.form.on("Purchase Receipt", "items", function(frm, cdt, cdn) {
   console.log("I am there");

Never reched the console.log command. Trigger not fired on table field change.
Any suggestion?

hi @emakis,

there are _add and _remove triggers available for child table,
please check

Thanks, Makarand

Thank you @makarand_b for your response. I knew those triggers but I need the trigger on update of any field of the table


frappe.ui.form.on("Purchase Order Item", "item_code", function(frm, cdt, cdn){
	// your code

item_code field trigger For Purchase Order Item Child table.

Thanks, Makarand


ty @makarand_b

Hi! I also have a similar problem, although it’s more on refreshing and showing the updated values of the child table. Console.log shows me that the data has been updated. But the field that I’m trying to update isn’t updating/changing. I’ve already tried using refresh, refresh_field(“items”, refresh_fields(). Sadly, I’m still stuck. Here’s my code:

var itm_warehouse = '';
var item_selected;

frappe.ui.form.on("Purchase Order Item", "item_code", function(frm, cdt, cdn){
    item = locals[cdt][cdn];
    item_selected = item;
            method: "itm_corp_app.itm_corp_app.doctype.itm_warehouse_setup.itm_warehouse_setup.get_warehouse",
           args: {
            callback: function(r, rt) {
            if (r.message)
                    itm_warehouse = r.message;
                    item.warehouse = itm_warehouse;
                    console.log("WH:"+locals[cdt][cdn].warehouse+" CDN:"+cdn+" CDT:"+cdt);



Try setting the value using the set_value method.

e.g. frappe.model.set_value(child.doctype,, field, value);

Thanks, Makarand

1 Like

Hi, @makarand_b! I already tried this one, sadly it still didn’t work. If i output the content of item_warehouse in the console and print it using a python script, it actually displays the changed data. Only the form field for warehouse won’t update.

By the way, warehouse is a linked field which is linked to the Warehouse doctype. I’m not sure if that’s one of the reasons why it doesn’t work.

HI @makarand_b, I wish to do the same for ToDo Doctype, which is added as a child table to a Consignment table. How do you determine the field that will change all the time?

I actually want to update reference_type and reference_name automatically to set “Consignment” as the doctype and the consignment_number as the docname.

description: function(frm) {
ToDo.reference_type = frm.doctype;
ToDo.reference_name = frm.docname;

Tried above but it didn’t work, doesn’t look like it is firing the code.

1 Like
[quote="aakvatech, post:15, topic:7070"]

I didn’t understand completely but as per understanding, I’m suggesting you.

If Consignment is parent table and todo is a child table. Here child table will save a parent doctype and its name.

validate: function(frm) {
var child = frm.add_child("todo");
				child.reference_type = frm.doctype;
				child.reference_type = frm.doctype;

So essentially, each Todo is a child of Container. I need to have all todo listed for easy reference and so added it as a child table. The reference type should be set as “Container” automatically and reference_name should be set as container.docname

Hope it clarifies the intent.

This worked

frappe.ui.form.on(“ToDo”, {
description: function(frm, cdt, cdn) {
var cur_doc = locals[cdt][cdn];
cur_doc.reference_type = frm.doctype;
cur_doc.reference_name = frm.doc.container_number;