Hi,
I have Link field in my doctype which points to user doctye. When I click it I get a dropdown listing all users.
I need a list of male users. How can I filter that dropdown to have only male or female users.
Hi,
I have Link field in my doctype which points to user doctye. When I click it I get a dropdown listing all users.
I need a list of male users. How can I filter that dropdown to have only male or female users.
It is possible by using get_query method and you have to write custom script for that. Refer following example -
cur_frm.fields_dict['user'].get_query = function(doc) {
return {
filters: {
"gender": 'Male'
}
}
}
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.
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"
}
}
}
hi @jyotinb,
if you need a dynamic filter, then you need to
@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