ERPNext Conference 2019* ERPNext.com Blog

Need Help Using FILTERS


#1

Greetings to all,

Trying below filters but it seems they are not working and it only fetches the latest row updated in Item Price, kindly suggest: (selling_price_list is in Sales Order && item_code is in Sales Order Item)

frappe.call({                        						
                         method: "frappe.client.get_value", 						
                         args: { 						
                                doctype: "Item Price",						
			        fieldname: "itemmrp",			
			        filters: { item_code: frm.doc.items.item_code, price_list: frm.doc.selling_price_list},			
                         },						
                         callback: function(r) {

While it works fine with explicit values:

frappe.call({
                         method: "frappe.client.get_value",
                         args: {
                                doctype: "Item Price",
			        filters: { item_code: ["=", "Item1"], price_list: ["=", "PriceList1"]},
				fieldname: "stamount",
                         },
                         callback: function(r) {

#2

@Faraz,

items is array of child table row you will need to pass the index of the row for which you wish to filter


#3

@makarand_b,

Hi and thanks. This is full script used on item_code trigger:

I thought WHILE could be used if it was on VALIDATE Trigger? Maybe I am wrong; Kindly suggest.

frappe.ui.form.on('Sales Order Item', 'item_code', function(frm, cdt, cdn){
frappe.call({
                         method: "frappe.client.get_value",
                         args: {
                                doctype: "Item Price",
			        filters: { item_code: ["=", frm.doc.items.item_code], price_list: ["=", frm.doc.selling_price_list]},
				fieldname: "stamount",
                         },
                         callback: function(r) {
                                          frappe.model.set_value(cdt, cdn, "test_price", r.message.stamount);
frm.refresh_field("items");
                         }
                });
});

#4

Try frm.doc.items[0].item_code. Replace ‘0’ with the index of the child table item.


#5

Thanks @pratu16x7,

I am missing the point here that I don’t know where to put while loop with frappe.call; and yes that would be good on Validate Trigger I guess. Kindly suggest.

Yes, I got the correct value using index, but it needs to be done with all the sales order items which are being inserted.

Tried below:

frappe.ui.form.on('Sales Order Item', 'item_code', function(frm, cdt, cdn){
var tbl = frm.doc.items || [];
var i = tbl.length;
while (i--) {
frappe.call({
                         method: "frappe.client.get_value",
                         args: {							
                                doctype: "Item Price",
			        filters:
				{ item_code: ["=", frm.doc.items[i].item_code], price_list: ["=", frm.doc.selling_price_list]},				
				fieldname: "stamount",			
                         },							
                         callback: function(r) {							
                                          frappe.model.set_value(cdt, cdn, "test_price", r.message.stamount);							
frm.refresh_field("test_price");
                         }							
                });							
});

#6

A lot of thanks; it worked after defining:

var cdoc = $('.data-row.editable-row').parent().attr("data-name”);


#7

@Faraz - Is it possible to provide the full script that eventually worked ?

Many Thanks