Help Filtering Child Items based on same child table field

This is the case:

In doctype UOM i have created a child doctype wich contains a new field called uos
In Quotation Item i have a custom field called UOS.

i am trying to filter the uos field in quotation child table based on item stock_uom

for example UOM doctype has
Kg
---- uos Child Table contains
pounds
ounces
grams.

In quotation item when selection any item wich stock_uom is kg the uos values should only those.

Hello,

You might have to write a custom script to make it work. If you have written any, and needs help in debugging, please share that custom script here.

Hello @umair umair thanks for feedback i know how to custom scrips works as for parent doctype and for child tables base in parent doctype field. this one is diferent and i could not find any example before posting my question.

My custon scrips looks like this

frappe.ui.form.on("Quotation", "refresh", function(frm) {
cur_frm.fields_dict['items'].grid.get_field('uos').get_query = function(doc, cdt, cdn) {
	return {
		filters:[
			['parent', '=', 'Kilogramo']
		]
	}
}
});

That scrip work if i want to filter only the UOS under Kilogram parent Doctype but i want to make it dinamic by using the stock_uom field in quoation item doctype

@rohit_w @kolate_sambhaji can you help?

I’m looking to do the same thing in the next couple of days, and I’ll be watching this thread. The most immediate comparison I could think of was this:

which looks very similar to what you have done already… I don’t know if the selection is dynamic… I believe Rohit mentioned something about asynchronous behavior of JS that creates difficulty for client side scripting of these things.

2 Likes

thanks for pointing out a solution the scrip works as this:

frappe.ui.form.on("Quotation", "refresh", function(frm) {
frm.fields_dict['items'].grid.get_field('uos').get_query = function(doc, cdt, cdn) {
child = locals[cdt][cdn];
			return{	
		filters:[
			['parent', '=', child.stock_uom]
		]
	}
}
});

Now is filtering uos based on a field in each row at child table.

Thank again!

3 Likes

Great! Good to hear; I’ll be doing that soon. Thanks

We have used something like this

frappe.ui.form.on("Delivery Note", "refresh", function(frm) {
	frm.fields_dict['items'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) {
		var child = locals[cdt][cdn];
		//console.log(child);
		return {	
			filters:[
				['en', '=', child.en]
			]
		}
	}
});

Similar use case… Sales Invoice -> items - filter UOM field based on Item selected in row.

frappe.ui.form.on("Sales Invoice", {
  setup: function (frm) {
    frm.set_query("uom", "items", function (doc, cdt, cdn) {
      let row = locals[cdt][cdn];
      return {
        query:
          "erpnext.accounts.doctype.pricing_rule.pricing_rule.get_item_uoms",
        filters: {
          value: row.item_code,
          apply_on: "Item Code",
        },
      };
    });
  },
});

related discussion:
https://discuss.erpnext.com/t/filter-link-based-on-child-table-field-on-other-doctype/25898/5

In Erpnext:

frappe.ui.form.on(“Purchase Receipt References”, “item_code”, function(cur_frm,cdt,cdn) {
console.log(“Start”)
var d = locals[cdt][cdn];
cur_frm.fields_dict[purchase_receipt_references_c].grid.get_field(‘type’).get_query =
function() {
return {

    filters: {
    	['parent', '=', child.item_code]

    }}}});

not able to run?