How to add a Custom Query for a Script Report Filter

Hi,

I am trying to add a custom query to a script report filter “js” file. The code I am trying to use is as below but obviously its not working. Please let me know how to correct this code:

frappe.query_reports["Item Report"] = {
    "filters": [
        {
            "fieldname":"bm",
            "label": "Base Material",
            "fieldtype": "Link",
            "options": "Item Attribute Value",
            "get_query": 
                        frappe.call({
                            'method': 'frappe.client.get_list',
                            'async': false,
                            'args': {
                                'doctype': 'Item Attribute Value',
                                'filters': ['parent', '=', 'Base Material'],
                                'fields': ['attribute_value']
                            },
                            'callback': function(res){
                                res.message.attribute_value
                            }
                        });

        }
    ]
}

bump

I have been able to resolve this query thanks to @max_morais_dmm but there seems to be a small issue. The link field is a child table and hence I am shown only the ID when I select the value but I want to show Only the attribute_value in the filter and not the ID. Is that possible?

frappe.query_reports["Item Report"] = {
	"filters": [
		{
			"fieldname":"bm",
			"label": "Base Material",
			"fieldtype": "Link",
			"options": "Item Attribute Value",
			"reqd": 1,
			"get_query": function(){ return {'filters': [['Item Attribute Value', 'parent','=','Base Material']]}}
		},

Now here is the output which is fine but I want to select by the attribute_value and not ID of the table, see the image below:

@max_morais_dmm is the customization star :smile:

@adityaduggal I don’t think that is customizable, you might want to write a custom query in a whitelisted method and call it rather than using filters.

1 Like

@rmehta but It will work for a Link field? Can you provide a sample?

Pass a method as string in get_query (https://github.com/frappe/frappe/blob/develop/frappe/public/js/frappe/form/control.js#L1165)

"get_query": "myapp.mymodule.mymethod"
1 Like

Can you give a more direct hint as I am unable to understand how could I get it to work for this function:

function(){ return {'filters': [['Item Attribute Value', 'parent','=','Base Material']]}}