Knowing the count of filtered employees

Hi All;
I need to know the number of employees of certain specification. In other words, I need to know the number of filtered employees (the filter will be based on certain conditions). Do I need to use frappe.db.count or fappe.get_all?

I know that frappe.db.count(‘Employee’) will return the number of employee documents, but I do not know how to use it with filter.
Also, I know that I can use frappe.get_all with filter, but I do not know how to know the count of the returned values.

Appreciate the kindly help.
Regards
Bilal

@bghayad,

you can use the frappe.db.count same as frappe.get_all just pass the doctype and filters
e.g. frappe.db.count("Employee", filters={'company': 'Wind Power LLC'})

Thanks a lot.
This function, I can use it in python. Is there equivalent for it that I can use it in .js files?
Actually, when I am using such functions in python, and it was related to button, the problem that I need to display the resulted data on the form and the resulted data is not only one parameters, it is a lot of parameters (because I need to count too many cases and return the results of each case). So how I can return a multiple parameters to the java script if I used the frappe.call function and the callback? I am afraid the returned r can contains only 1 parameter, so in this case I have to use frappe.call function for each parameter. Appreciate the advise.
Regards
Bilal

@bghayad,

No, currently there is no method available to get the count of documents from js, You will need to write the whitelisted method to get the count.

Thanks,
Makarand

Using whitelisted method and using frappe.call, how I can return 3 or 4 parameters that were calculated in the whitelisted method to the frappe.call at the .js that used to call the whitelisted method?

Regards
Bilal

OK I resolved this problem. I can return the parameters as arrays (separating them by ,) and I can call them again using r.message[0] and r.message[1], … etc.

But the problem now in the filter: Is it possible to use OR operators? Because I need to filter based on multiple ORing cases. How?
As I know that filtering based on AND is possible.

Thanks for the kindly help.
Regards
Bilal

If it is not possible to use OR in filter, what is the alternative method of the frappe.db.count to be used?
Regards
Bilal

To simplify the request:
I need to get the count of employees who their employment type is “board member” or “contract”, how?
Regards
Bilal

frappe.db.count("Employee", filters={"employment_type": ["in", ("board member", "contract")]})

Thanks a lot @Sangram for kindly help.
But now I am facing another condition that required to use OR operator:
I need to find the count for employee which their status is active or relieving_date is > some_date, how I can achieve this using filers and using frappe.db.count?

Regards
Bilal

use frappe.db.sql()

1 Like

Thanks for the help.
But why the filter is not supporting OR operator? When it is expected to be ready?
Regards
Bilal