Set the options for a Select field in a Child Doctype using serverside script

I am trying yo set the options for the child table field using frappe.call . I have done this for Doctype field but am unable to do this for child table field.

frappe.ui.form.on("Support EXP", {

    refresh: function(frm) {
		if(frm.doc.project){
		
			frappe.call({
				method: "frappe.support_application.doctype.support_exp.support_exp.get_Modules",
				args: {
					project: frm.doc.project
				
				},
				callback: function(response) {
					var options = response.message;
					frm.set_df_property("module", "options", options);
					
					
			
					
				}
			});
		}
    }
  });

Here I am calling a serverside method to auto populate the module field according to the project

hey @NCP could you help with this

Hmm :thinking: @Parth_Vashista,

Okay!

Please check the syntax.

frappe.ui.form.on("Child Table Name", {
    field_name_which_trigger_to_server_call: function(frm, cdt, cdn) {
        var row = local[cdt][cdn];
        if(frm.doc.project) { // if you want to choose child table fieldname then use d.child_table_field_name
            frappe.call({
                method: "frappe.support_application.doctype.support_exp.support_exp.get_Modules",
                args: {
                    project: frm.doc.project // or child table field name
                },
                callback: function(response) {
                    var options = response.message;
                    // Your Data
                }
            });
        }
    }
});

More reference:

I hope this helps.

Thank You!

I tried the above code for triggering the function on select field of child Table, its working.
Now I am trying to use it to trigger a function that dynamically populate the options in select field of the same child table, I am getting the values from the back end, but its not showing in options.

Master Table: Weapon In, Child Table: Weapon In Details.
I want to populate the select field named Shelf based on the selection in Storage ID field.

Code:

frappe.ui.form.on("Weapon In Details", {
    storage_id: function(frm, cdt, cdn) {
        var row = locals[cdt][cdn];
        var storageId = row.storage_id;
        var unitLocation = frm.doc.unit_location; 

        if (unitLocation && storageId) {
            frappe.call({
                method: 'weapon_management.weapon_management.doctype.weapon_in.weapon_in.get_shelf_options',
                args: {
                    unit_location: unitLocation,
                    storage_id: storageId
                },
                callback: function(response) {
                    var options = response.message;
                    console.log(options);
                    frm.set_df_property("shelf", "options", options,'weapon_in_details');
					
                }
            });
        }
    }
});

Added the Screenshot for reference


.


set_df_property(fieldname, property, value, docname, table_field, table_row_name = null) {
        let df;

        if (!docname || !table_field) {
            df = this.get_docfield(fieldname);
        } else {
            const grid = this.fields_dict[fieldname].grid;
            const filtered_fields = frappe.utils.filter_dict(grid.docfields, {
                fieldname: table_field,
            });
            if (filtered_fields.length) {
                df = frappe.meta.get_docfield(
                    filtered_fields[0].parent,
                    table_field,
                    table_row_name
                );
            }
        }

        if (df && df[property] != value) {
            df[property] = value;

            if (table_field && table_row_name) {
                if (this.fields_dict[fieldname].grid.grid_rows_by_docname[table_row_name]) {
                    this.fields_dict[fieldname].grid.grid_rows_by_docname[
                        table_row_name
                    ].refresh_field(fieldname);
                }
            } else {
                this.refresh_field(fieldname);
            }
        }
    }

This is what i found in form.js but this is not working as given @NCP

frm.fields_dict.{table field name in parent doctype}.grid.update_docfield_property(
{table field name you want to set options for}”,
“options”,
[“”].concat(fields)
);

this is the solution for setting the child table select field options