Setting default value in a child field using javascript

How do I set default value in a child field using javascript? So far I have this code does not work as intended. Score is a child doctype. I want to set a default value in the student field. Any ideas?

frappe.ui.form.on("Score", {
    onload: function (frm) {
        frm.set_value("student", "Testing");

@ccfiel there is a different call. Sorry again not documented you have to write an event on [table_fieldname]_on_form_rendered

Like: erpnext/delivery_note.js at develop · frappe/erpnext · GitHub

1 Like

@rmehta Thanks! but I do not know how to access the child field student?

frappe.ui.form.on("Grade Sheet", "score_on_form_rendered", function (doc, grid_row) {
    console.log("im here");
    doc.set_value("student", "Testing"); <--- error student field not found

Grade Sheet is the parent table and score is the field name Table type thats points to Score doctype. How can I access the field student that belogs to Score Child Doctype?

I have solve this problem with this code.

frappe.ui.form.on("Grade Sheet", "score_on_form_rendered", function (doc, grid_row) {
    var grid_row = cur_frm.open_grid_row();

@rmehta My solution did not work. It will set the the text box in the UI but when I click done the student value will be the first record in the query(dropdown) not the value set in the text box. Any idea how to resolve this? :slight_smile:

@rmehta Sorry the solution was correct. I just mess up other javascript that cause the problem. Thanks

1 Like