How to add custom script to child table?

I want to hide a field in child table.
In a new client custom script I click the “Add script for Child Table” button which select a child table and insert a script for the child table.
But it doesn’t affect anything.
It does work for the parent table.

//the parent:
frappe.ui.form.on('Delivery Note', {
	refresh(frm) {
		frm.set_df_property('is_return', 'hidden', 1);
	}
});

//the child:
frappe.ui.form.on('Delivery Note Item', {
	refresh(frm) {
		frm.set_df_property('rate', 'hidden', 1);
	}
});

Is there anything I should add to the code?
Thank you

Try this

frappe.ui.form.on("Delivery Note", {
	before_load: function(frm) {
		var df_rate = frappe.meta.get_docfield("Delivery Note Item", "rate", cur_frm.doc.name);
		df_rate.hidden = 1;
		frm.refresh_fields();
	}
});
1 Like

Yes it works for the popup child-table form (when click that triangle on the right). No longer rate field above amount field.
image

Now how do I also hide it from the table view in the parent doctype?
I try to use df_rate.in_list_view = 0 doesn’t hide the column from the table view.

1 Like

It should hide from the grid as well, maybe you just need to clear cache using “reload” and then you should be fine.

No it is not hidden on the grid.
I have reload, bench clear-cache, change browser.

Hello,

In my case I am trying to change the filter parameters in a child table but it’s not working. Here’s my script:

frappe.ui.form.on('Expense Claim Type', {
refresh(frm) {
 frm.set_query('payment_account', function() {
	});

frappe.ui.form.on('Expense Claim Account', {
	refresh(frm) {
        frm.set_query('payment_account', function() {
			return {
				filters: {
					'company': frm.doc.company,
					"is_group": 0,
				}
			}
		});
	}
})

Any ideas what I could be doing wrong

The below client script is correctly fetching data to Salary Slip doctype. However, the deduction/earnings are not updated based on the fetched field unless I press save button. Is there anyway that the deductions/earnings tables are refreshed when the field opt_in is updated?

frappe.ui.form.on(‘Salary Slip’, {
refresh: function(frm, cdt, cdn)
{
frappe.call({
method:“frappe.client.get_value”,
async:false,
args:{
doctype:‘Lunch Mess Option’,
filters:{
employee:cur_frm.doc.employee
},
fieldname:‘opt_in’
},callback:function(r){
console.log(r.message);
if(r.message !== undefined){
cur_frm.set_value(‘opt_in’,r.message.opt_in);
frm.refresh_field(‘opt_in’);
frm.refresh_fields();

    }
}

});
}});

@flexy2ky i am stuck with the same issue rn.

Try using this

fieldname_of_parent_docs_variable: function (frm) {

    var schedule_due = frappe.meta.get_docfield(
      "Childtable Name" , // i.e., Sales Invoice Item
      "due_month",
      frm.doc.name
    );

      schedule_due.read_only = 1;
      if (frm.fields_dict["fees"].grid.grid_rows.length > 0) {
        // Access grid_rows properties here
        frm.fields_dict["fees"].grid.grid_rows.forEach(function (row) {
          row.doc.discount = row.doc.amount;
        });
      }
      frm.fields_dict.fees.grid.wrapper.find(".grid-add-row").hide();
      frm.fields_dict.fee_installments_schedule.grid.wrapper
        .find(".grid-add-row")
        .hide();
  }

Hi @rahy

Did you find a solution ?

no I didn’t and haven’t