on refresh parent doctype i want dynamic select option for childtable like this
if(childtable_row.financier == "test"){
status.options = ["A",'B']
}else{
status.options = ['c']
}
on refresh parent doctype i want dynamic select option for childtable like this
if(childtable_row.financier == "test"){
status.options = ["A",'B']
}else{
status.options = ['c']
}
Hi @pratikcws,
if(row.financier == "TEST")
{
set_field_options("status", ["Loan Approved","Loan Appealing"])
}
else
{
set_field_options("status", ["Loan Accepted"])
}
And More details of script: Filter Options in Select Field
https://docs.erpnext.com/docs/v12/user/manual/en/customize-erpnext/custom-scripts/filter-options-in-select-field
Thank You!
this will work for parent doc but not for child table
Hi @pratikcws,
If you have not check so check it for just small help.
and you have a find any solution then put in this topic.
Thank You!
Hi @pratikcws,
I got a solution.
Please check it.
it works for my side in child table.
if(row.financier == "TEST")
{
frm.fields_dict.items.grid.update_docfield_property("status","options",["Loan Approved","Loan Appealing"]);
}
else
{
frm.fields_dict.items.grid.update_docfield_property("status","options",["Loan Accepted"]);
}
Thank You!
Which version of ERPNext is it working for?
12 and 13 both.
I am getting the following error:
frm.fields_dict.items.grid.update_docfield_property is not a function
at refresh (eval at setup (script_manager.js:160:5), :30:39)
at a (script_manager.js:90:16)
at script_manager.js:108:22
Thank you so much @NCP
This is an easy way to do a version of set_field_options() on the child table. Hope this helps others too.
Here’s how I used it today:
frappe.call({
method: "frappe_mailjet.frappe_mailjet_integration.doctype.mailjet_settings.mailjet_settings.get_doc_fields",
args: {
"doc": frm.doc.for_doctype
},
callback: function(r) {
frm.fields_dict.custom_fields.grid.update_docfield_property("field_name","options", r.message);
}
});
Note: my child table is called custom_fields and my field is called field_name
@NCP @adam26d Not Working in my side , my child table field name is items
frappe.ui.form.on("Purchase Order Item", 'expense_account',function(frm,cdt,cdn) {
var row = locals[cdt][cdn];
if (row.expense_account == 'Machinery Hiring - PVIPL') {
frm.fields_dict.items.grid.update_docfield_property("expense_perticulers", "options", ["Loan Approved", "Loan Appealing"]);
}
else {
frm.fields_dict.items.grid.update_docfield_property("expense_perticulers", "options", ["Loan Accepted"]);
}
})
Hello @Sagar_Patil
My first hunch of your problem is that this function might be unreachable.
Put a console.log("working");
after var row = locals[cdt][cdn];
To verify that the code is running.
In my case i ran this thing using a parent doctype event. Child events are counterintuitive sometimes.
No, function is working fine, i think Child’s problem. Is there any other way ? cause i need to add select options on child field’s event
Credit to this post for helping me come up with a solution:
To clarify further, as well as to update existing rows in case the dynamic options have changed, I did the following:
// Inital Setup, courtesy of linked post's author
frappe.utils.filter_dict(
cur_frm.fields_dict["YOUR_CHILD_TABLE_NAME"].grid.docfields,
{ "fieldname":"NAME_OF_SELECT_FIELD_IN_CHILD_TABLE" }
)[0].options = YOUR_LIST_OF_OPTIONS;
// Additional code:
// To refresh the existing select fields in the child table when your list of options change.
// The code above only affects new rows in the child table.
const EXISTING_ROWS_IN_CHILD_TABLE = cur_frm.fields_dict["YOUR_CHILD_TABLE_NAME"].grid.grid_rows
for (row in EXISTING_ROWS_IN_CHILD_TABLE) {
frappe.utils.filter_dict(
EXISTING_ROWS_IN_CHILD_TABLE[row].docfields,
{ "fieldname":"NAME_OF_SELECT_FIELD_IN_CHILD_TABLE" }
)[0].options = YOUR_LIST_OF_OPTIONS_WHICH_HAS_BEEN_EDITED;
}
// Save the changes
cur_frm.refresh();
I run this code during the onload
event, as well as any other events where the list of options could change. For instance, in my case, my list of options is from another child table, so I also run the above code when there are new rows or edited values in that child table.