How to do something when we press Add New Row in child table

Hi all,

Which java script function can i use to do something when we press add new row in child table?

Hi @ninjas005
This might help you
https://frappe.github.io/frappe/user/en/guides/app-development/trigger-event-on-deletion-of-grid-row.html

1 Like

Thanks @ravindra_l,

That Works!!!

How can i do something after a row is added?

frappe.ui.form.on("Journal Entry Account", "accounts_add", function(frm){
        cur_frm.cscript.update_totals(frm.doc);
});

The above code gets triggered before the row is added.
How do i know or trigger something after adding the row?

i tried like

frappe.ui.form.on("Journal Entry Account", "after_accounts_add", function(frm){
        cur_frm.cscript.update_totals(frm.doc);
});

But didn’t work :wink:

Please help…

@ninjas005, in this case the ideal is use a field in the row, to trigger the event!

@ravindra_l

https://frappe.github.io/frappe/user/en/guides/app-development/trigger-event-on-deletion-of-grid-row.html this link is not working. Can you please send me the actual solution…?

(Moderator Note: The above link has been repaired.)

Hi @Baljeetsingh This is a live link
https://frappe.github.io/frappe/user/en/guides/app-development/trigger-event-on-deletion-of-grid-row.html

@ravindra_l Thanks for the fast response

@ravindra_l

is there any way to dectect done button is click or not ?

Because the following function is working when I press the remove button.
frappe.ui.form.on(“Journal Entry Account”, “accounts_remove”, function(frm){
cur_frm.cscript.update_totals(frm.doc);
});

Thanks And Regards
Baljeet Singh

@Baljeetsingh use frappe.ui.form.on(“Journal Entry Account”, “accounts_add”, function(frm)

1 Like

@ravindra_l
Yes its working when i am click on the “Add New Row” button of grid
frappe.ui.form.on(“Journal Entry Account”, “accounts_add”, function(frm){
cur_frm.cscript.update_totals(frm.doc);
});

but the same functionilty i want something as follow
frappe.ui.form.on(“Journal Entry Account”, “accounts_done”, function(frm){
cur_frm.cscript.update_totals(frm.doc);
});

Is there any option like thats when i will click on the done then my value will insert intp cell of each row.

@ninjas005 have you got the solution

How can i do something after a row is added?

frappe.ui.form.on(“Journal Entry Account”, “accounts_add”, function(frm){
cur_frm.cscript.update_totals(frm.doc);
});
The above code gets triggered before the row is added.
How do i know or trigger something after adding the row?

No, I’ve done some adjustments.
I’ve added triggers to almost every fields in the child table and also added trigger when removing the row.
It worked for me.

Hello,

Could you please give a hint on how you added the trigger after adding a new row?

Thanks in advance,
Sorin

@sorin.negulescu,

check the example for child table add event in sales_invoice.js,

similarly you can add the custom script for the child table add event

frappe.ui.form.on('YourDocType', 'childtable_fieldname_add', function(frm){
	// Your code
});

Thanks, Makarand

1 Like

Hi,

Thank you for your solution! Unfortunately, I was not able to make it work.
I am trying to have a function called after a new Operation is added to the BOM.

This is what I am referring to:

That function would sum the operation times and display it below the table (like the cost is):

For this, I added in the BOM DocType, the operating_time field.

Sorin

@sorin.negulescu
It should work as per makarand_b’s suggestion.
Please share script you are trying.

Thank you @Nick, but I was looking for a solution that would not involve any changes in the source files. I wanted to make it work from the interface.

@ninjas005
I have a question if you can help please:
How can you know the row # that the change is happened in it?
For example: if the change happened at row # 1 or row # 2 or row # 3?
Why I need this information? Because I need to set the value of the next field of the changed field at that row and I do not need to change the values of other rows.

Regards
Bilal

I am not sure this is helpful for you ,

//parent_table_doctype.js
frappe.ui.form.on('Child Table Doctype', {
	onload: function(frm,cdt,cdn) {
		// do your stuff
	},
	refresh: function(frm,cdt,cdn) {
		// do your stuff
	},
	changed_field_in_child_table: function(frm,cdt,cdn) {
		// do your stuff
		the_new_value_for_changed_field = locals[cdt][cdn]['changed_field_in_child_table']
		value_of_field_in_same_row 				= locals[cdt][cdn]['field_name_in_same_row']
	},
});