Need explanation

{
	"fieldname":"item_code",
	"label": __("Item"),
	"fieldtype": "Link",
	"options": "Item",
	"get_query": function() {
		return {
			query: "erpnext.controllers.queries.item_query"
		}
	}
}

The above file is in script report of js file.Here i want to know what does the "get_ query " function perform.where can i found "“erpnext.controllers.queries.item_query” ??? waht does it mean

In get_query you can specify a customized query result for Link type docfields. You can write your own Python function running your own MySQL query and get results by the parameters you wish.

This notifies in which file what function to use. If you check ERPnext’s directory structure - you will find folder by the name controllers and inside is a python file named queries.py in which the function item_query is defined.

Edit : This you can do this not just via the Python route but also the JS route. Like this:

In Doctype

frm.set_query('employee', function (frm) {
        return {
            "filters": {
                "company":"Lehmann Brothers"
            }
        }
    });

And in script reports:

{
    fieldname:"employee",
    label: __("HR Personnel"),
    fieldtype: "Link",
    options: "Employee",
    get_query: function(){
        return{
            filters : {
                'company' : 'Lehmann Brothers',
                'department' : 'HR',
                'status' : 'Active'
            }
        }
    }
},
{
    fieldname:"supplier",
    label: __("Supplier"),
    fieldtype: "Link",
    options: "Supplier",
    get_query: function(){
        return{
            filters : {
                'disabled' : 0,
                'supplier_type' : 'Services',
                'supplier_warehouse': ['not like', '']
            }
        }
    }
},

ERPNext code has a number of such examples so try and explore more of them

2 Likes

@root13F Thank you

you had another query, are you okay with it now ?

@root13F Yes, Thank you