How can I do the same in a child form?
(ie, if user field is in the child form)
@ninjas005 You can also use this -
cur_frm.fields_dict["child_table_fieldname"].grid.get_field("user").get_query = function(doc){
return {
filters:{
"gender": "Male"
}
}
}
Check out Mode of Payment in ERPNext.
There is a docfield “accounts” in Mode of Payment with type “Table”.
“account” field is a child table “Mode of Payment Account”.
default_account is the field in child table which is to be filtered.
Need help with two things.
- How can I change a value in the child form, when I change a value in the same form?
- Also change the value in the parent form, when i change the value in the child form?
Something like how “source warehouse” in the row in items of Stock Entry is selected?
Checkout stock_entry.js
Something like how BOM calculates raw material cost from rows in items? Checkout bom.js
I want to filter item_code in child table based on custom field brand_name
My parent doc name: Delivery Note
child table : Delivery Note Item ( field_name : items)
i had added following script in “Delivery Note” custom script but not working. Please help
cur_frm.fields_dict[‘items’].grid.get_field(‘item_code’).get_query = function(doc) {
return{
filters:[
[‘brand’, ‘=’, brand_name]
]
}
}
@jyotinb , Please try with following code :
frappe.ui.form.on("Delivery Note", "onload", function(frm, cdt, cdn){
frm.set_query("item_code", "items", function(cdt, cdn) {
var c_doc = locals[cdt][cdn];
return {
"filters": ['brand', '=', c_doc.brand_name]
};
});
});
Thanks for fast reply
Not working
copy script in custom script of “Delivery Note” custom script is ok?
My query again with clear documentation.
I want to filter item_code in Delivery note based on field brand_name
(both item_code & brand_name are in child table Delivery Note Item (field name items))
I had created extra field ‘i1’ type link field and options Item (same as item_code)
-
My following code works pefectly for 'i1' , but not for 'item_code'.
cur_frm.fields_dict[‘items’].grid.get_field(‘i1’).get_query = function(doc) {
return {
filters: {
"brand": "brand1"
}
}
}
- and how to refer dynamic filter field
‘brand_name’ instead of fixed value “brand1”.
hi @jyotinb,
if you need a dynamic filter, then you need to
- get the value with which you need to filter (use get_value) in onload
- then you apply the filter with that value.
3 then you refresh listview
@priya_s Hi, I’ve tried the code but it won’t categorize our list??
Here’s the code:
cur_frm.fields_dict[‘requested_by’].get_query = function(doc) {
return {
filters: {
“Operations”: doc.department,
“Admin”: doc.department,
“Sales”: doc.department,
“Engineering”: doc.department,
“Legal”: doc.department,
“Purchase”: doc.department,
“Marketing”: doc.department,
“Human Resources”: doc.department,
}
}
}
@kelscey90, something is incorrect in code.
By seeing screenshots,as per my understanding you have to show only those employee in drop down which having department “Engineering”.
so in filter you have write only department value,in filter try with this-
filters: {
“department”: doc.department
}
@priya_s Yes I only need to show those people who are engineers only when engineering is chosen. But it kept showing everyone. I’ve tried your custom script but is still wont categorize it?
This is my overall script:
frappe.ui.form.on(“Stock Request”, “onload”, function(frm, cdt, cdn, doc, dt, dn){
frm.add_fetch(“item_code”, “description”, “description”);
frm.add_fetch(“item_code”, “item_name”, “item_name”);
frm.add_fetch(“item_code”, “stock_uom”, “uom”);
frm.add_fetch(“item_code”, “item_group”, “item_group”);
frm.add_fetch(“item_code”, “brand”, “brand”);
frm.add_fetch(“requested_by”, “Non-Alcon Personnel”, “non_alcon_personnel”);
frm.add_fetch(“tc_name”, “terms”, “terms”);
frm.set_value(“date_requested”, frappe.datetime.add_days(frappe.datetime.nowdate()));
})
cur_frm.fields_dict[‘requested_by’].get_query = function(doc) {
return {
filters: {
“Department”: doc.department,
}
}
}
If you are using default Department form try with this in filter-
“department_name”: doc.department
Thanks, Priya
@priya_s still won’t work. Btw I have 2 field which is a link type and a select type. I copied the name on the employee module list and inserted it on the select type field. Is it correct?
Can you please share screen-shots?