Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

"IN" operator for addWhere() not returning data #207

Open
antipode3141592 opened this issue Nov 22, 2019 · 3 comments
Open

"IN" operator for addWhere() not returning data #207

antipode3141592 opened this issue Nov 22, 2019 · 3 comments

Comments

@antipode3141592
Copy link

I'm having trouble getting results when using the "IN" operator in where clauses to search for multiple options (ex: search for all contacts that have selected both Volunteering and Newsletter among their contact preferences).

Using the API4 Explorer, this is php output

$contacts = \Civi\Api4\Contact::get()
  ->setSelect([
    'id', 
    'contact_type', 
    'display_name', 
    'Interests.Contact_Interests',
  ])
  ->addWhere('Interests.Contact_Interests', 'IN', ['Volunteering', 'Newsletter'])
  ->setLimit(25)
  ->execute(); 

Which yields no results. Notably, when I switch 'IN' to 'NOT IN', it returns all contacts with non-empty Contact_Interests, so it seems like this is an API issue.

Using the API3 Explorer:

$result = civicrm_api3('Contact', 'get', [
  'sequential' => 1,
  'return' => ["id", "contact_type", "display_name", "custom_25"],
  'custom_25' => ['IN' => ["Newsletter", "Volunteering"]],
]);

This call does return the correct results.

@colemanw
Copy link
Member

Which version of api4 are you using? This extension or the one in core?
Is this a multiselect custom field or does it hold a single value?
And are "Newsletter" and "Volunteering" the option names or ids or labels or what?

@antipode3141592
Copy link
Author

CiviCRM 5.18.3 with API extension 4.5.2. I am trying to search on a multiselect custom field (Set name is Interests, and the options Newsletter and Volunteering are both the label and the value).

@colemanw
Copy link
Member

Multiselects are tricky because of the way the data is serialized. I don't think api4 has been taught that trick yet.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants