Hi,
I am trying to trigger an event when adding a new row to a table. From what I understand, I just need to add the following to the Child DocType but I cannot get it to work…
frappe.ui.form.on('Board Test', {
test_procedures_add: function (frm) {
console.log('Added Test Procedure...');
},
})
Here are my settings on the Parent DocType…
When I press the Add New
button in the table located in the Parent, a Child is added but nothing in the console. Not sure what I am doing wrong, any help is appreciated!
Change Board Test
for the parent Doctype name. And try it.
Thanks but that did not seem to work either. Maybe I set something up incorrectly. I am trying to link a Board Test
DocType to a Serial No
DocType and populate Board Test
with some info from the Serial No
. Here is what I did…
-
Created a new DocType named Board Test
and set the Module to Manufacturing
(same as Serial No
, not sure if that matters or not).
-
I set up Board Test
as follows…
-
Customized Serial No
and added a Table…
- Label: Test Procedures
- Type: Table
- Name: test_procedures
- Options: Board Test
-
Created a new js script for Board Test
and added the following…
frappe.ui.form.on('Serial No', {
test_procedures_add: function(frm) {
console.log('added!');
}
});
The DocTypes are linking but I do not know how to pass data from Parent to Child. I figured this would happen when pressing Add Row
button on the table and fire an event, but maybe this is incorrect? I guess what I am trying to do is set the serial_no
field automatically in the Board Test
DocType (Child) when it is created from the Serial No
DocType (Parent). Not sure if this is possible or not.
Ok, sorry I took so long. If I understand what’s wrong, Here’s what neeeds changing.
- In the Board Test Doctype, check the box
is Child Table
.
- Remove the Serial No link field. (Why? read below).
The reason you remove the Serial No link field is because It’s a child Table, and child table by default have a Field named parent
that parent field is taken care by Frappe itself. So when you are In a Document from Serial No
Doctype and you have your table field. When you fill it / create a new one, frappe behind your back will set the parent
fields on the Board Test
Doctype, to the current Serial No
document name.
I hope I was clear (I doubt it :D). Feel free to ask me again, in case I’m not clear. You can also get help in.
- ERPNext Help Public Telegram Group
-
ERPNext Discord not very active but hopping it picks up.
No worries. So when I check the is Child Table
box I no longer have access to the Board Test List. I would like this still for easy reference. I still could not get this to work so I went a different route.
I ended up just changing it to a combination of a Link
& Dynamic Link
Fields. Then run a custom script to auto-populate the Serial No
field in Board Test when creating a new entry.
board_test.js:
frappe.model.on("Serial No", "test_results", function(fieldname, value, doc) {
cur_frm.set_value("serial_no", doc.name);
});
Not sure if this is the best way or not but it works. Thanks for the help.
[EDIT] Fixed code block above.