Try ERPNext Buy Support Partners Foundation

Filter with IN in frappe.client.get_list

@AdityaHase
Was going to add to my post Filter with LIKE in frappe.client.get_list as is related, but it was closed.

Can now use LIKE in filters for frappe.client.get_list (thank you

Cannot get filter to work with IN.

This works filters: [[‘field_name’, ‘IN’, ‘single_field_name_value’],…

With field_names_string = “name1”,“name2”,“name3”

These do NOT work:

  • filters: [[‘field_name’, ‘IN’, field_names_string],…
  • filters: [[‘field_name’, ‘IN’, ‘(’, field_names_string, ‘)’],…
  • filters: [[‘field_name’, ‘IN’, ‘(’+field_names_string+’)’],…

Neither does field_names_string = ‘(“name1”,“name2”,“name3”)’

@tonto
It should be

frappe.db.get_list(doctype_name, \
filters=[[ field_name, 'IN', ['value1', 'value2', 'value3'..]]]) 

You have to pass a list of values not a string.

@abhishekbalam
Thank you. For those less javascript proficient, like me, an array passes as a list so this worked

filters=[[ field_name, ‘IN’, value_array]])