Frappe.get_list empty

Am having trouble finding out how to use frappe.get_list. It seems to always return an empty list. Anyone knows why?

Im in the Journal Entry screen and I want to get a list of all the Accounts that are of type tax. The following is the code that I’m trying:

frappe.get_list("Account", {account_type: "Tax"})

This returns an empty list.

Maybe, you want

frappe.get_list("Account", filters={"account_type": "Tax"})

Check the example here, https://frappe.github.io/frappe/user/tutorial/controllers.html

@pdvyas i just tried your recommendation:

frappe.get_list("Account", filters={"account_type": "Tax"})

but it still returns an empty list. Are you able to get results on your side?

Based on the example link you provided I also tried the following:

frappe.get_list("Account",
        fields=["name", "company"],
        filters = {
            "account_type": "Tax"
        })

also returns an empty list.

Yeah, on the demo instance,

In [5]: frappe.get_list("Account", filters={"account_type": "Tax"})
Out[5]:
[{'name': u'Service Tax - NETL'},
 {'name': u'Excise Duty @ 4 - NETL'},
 {'name': u'Excise Duty @ 8 - NETL'},
 {'name': u'SHE Cess on TDS - NETL'},
 {'name': u'Edu. Cess on TDS - NETL'},
 {'name': u'Excise Duty @ 10 - NETL'},
 {'name': u'Excise Duty @ 14 - NETL'},
 {'name': u'SHE Cess on Excise - NETL'},
 {'name': u'Edu. Cess on Excise - NETL'},
 {'name': u'SHE Cess on Service Tax - NETL'},
 {'name': u'Edu. Cess on Service Tax - NETL'}]

what screen are you on when you run this in the console?

@pdvyas I’m actually using javascript not PY

@bohlian

the javascript frappe.get_list is for documents that are already available in the client. Sorry for the confusion.

You will have to use ajax and rest API or frappe.call and frappe.client.get_list

-Anand.

@anand, thank you, makes sense now.

Can I ask then is there a way to pass a parameter to a frappe.call’s callback function? E.g. i want to pass some_parameter in the following example:

var some_parameter = “hello”;

frappe.call({
	method:"frappe.client.get_value",
	args:{
		doctype:"Account",		
		filters: {
			'account_type': "Tax"
		},		
		fieldname: "name",
	},
	callback: function(r, some_parameter) {		
		console.log(some_parameter);
	}
});
1 Like

You can use the closure pattern for this:

function dosomething() {
	var some_parameter = "hello";
	
	frappe.call({
		method:"frappe.client.get_value",
		args:{
			doctype:"Account",		
			filters: {
				'account_type': "Tax"
			},		
			fieldname: "name",
		},
		callback: function(r) {		
			console.log(some_parameter);
		}
	});
}

Thanks @anand