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("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
}
});
}
}
});
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');
}
});
}
}
});
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