Answers.Body: <p>I think the feature you need is <a href="https://issues.civicrm.org/jira/browse/CRM-17096" rel="nofollow noreferrer">A 'contains' operation for the api to search multiselect custom values</a>, which is work in progress. See the associated <a href="https://github.com/civicrm/civicrm-core/pull/6612" rel="nofollow noreferrer">pull request #6612</a> for discussion of progress - it seems to have stalled but with good work already having been done.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T10:54:36.873Z
Answers.LastActivityDate: 2017-03-10T10:54:36.873Z
Answers.UserDisplayName: davejenx
Answers.Body: <p>May be try the below - If the below doesn't help then you need to write a sql for the same I guess </p>
  
  <pre><code>$result = civicrm_api3('Event', 'get', array(
    'sequential' =&gt; 1,
    'return' =&gt; array("custom_13"),
    'custom_13' =&gt; array('NOT IN' =&gt; array(2, 3)),
  ));
  </code></pre>
  
  <p>try to set unwanted category in "NOT IN" condition </p>
  
  <p>Thanks - I guess this helps!!!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T09:45:52.847Z
Answers.Text: Sorry, but you misunderstand my issue. It's ok, that the event is in category `2` or `3`, as long it is in `1`.
Answers.UserDisplayName: Philipp Michael
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T09:47:15.630Z
Answers.Text: did you try to run the same - this is giving you a list of category A from all the set -
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T12:39:30.237Z
Answers.Text: Oh, you seem to be right. But I don't understand why this works. Shouldn't 'NOT IN' exclude all events, that are in `2` or `3`, even though they are in `1`?
Answers.UserDisplayName: Philipp Michael
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T09:40:31.240Z
Answers.LastActivityDate: 2017-03-10T09:40:31.240Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.Body: <p>Because <a href="https://github.com/civicrm/civicrm-core/pull/6612" rel="nofollow noreferrer">#6612</a> has been closed I'm currently using <code>LIKE</code> as a workaround:</p>
  
  <pre><code>CRM.api3('Event', 'get', {
    "sequential": 1,
    "custom_1": {"LIKE":"%category A%"}
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
  <p>which is working fine if the value is not part of another value. E.g filtering by "<em>category A</em>" would also list events of "<em>category A</em>wesome".</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-08T14:05:29.560Z
Answers.LastActivityDate: 2018-02-08T14:05:29.560Z
Answers.UserDisplayName: Philipp Michael
Body: <p>I have an event with a custom field <code>custom_1</code> which is a multi select or checkbox list with two options <code>Category A</code> and <code>Category B</code>:</p>
  
  <pre><code>"custom_1": [
    "category A",
    "category B"
  ],
  </code></pre>
  
  <p>Now I'm trying to get all events which have at least option <code>category A</code>:</p>
  
  <pre><code>CRM.api3('Event', 'get', {
    "sequential": 1,
    "custom_1": "category A"
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
  <p>With this request I just get the events, which have <code>category A</code>, but not <code>category B</code>:</p>
  
  <pre><code>"custom_1": [
    "category A"
  ],
  </code></pre>
  
  <p>But I need all events with <code>category A</code>, regardless if they have another category. So events with this custom field values should also be returned:</p>
  
  <pre><code>"custom_1": [
    "category A",
    "category B"
  ],
  </code></pre>
  
  <p>Is it possible to make an API request like "Get all events which have <strong>at least</strong> one of this custom field options."?</p>
  
Tags: <civievent><custom-fields><api>
Title: CiviCRM API: How to get event by custom multiselect field option?
ThreadText: # CiviCRM API: How to get event by custom multiselect field option?
  
  (Asked by: username_0 on 2017-03-10)
  
  I have an event with a custom field `custom_1` which is a multi select or checkbox list with two options `Category A` and `Category B`:
  
  ```
  "custom_1": [
    "category A",
    "category B"
  ],
  
  ```
  
  Now I'm trying to get all events which have at least option `category A`:
  
  ```
  CRM.api3('Event', 'get', {
    "sequential": 1,
    "custom_1": "category A"
  }).done(function(result) {
    // do something
  });
  
  ```
  
  With this request I just get the events, which have `category A`, but not `category B`:
  
  ```
  "custom_1": [
    "category A"
  ],
  
  ```
  
  But I need all events with `category A`, regardless if they have another category. So events with this custom field values should also be returned:
  
  ```
  "custom_1": [
    "category A",
    "category B"
  ],
  
  ```
  
  Is it possible to make an API request like "Get all events which have **at least** one of this custom field options."?
  
  **Tags:** civievent, custom-fields, api
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2017-03-10. Score: 2
  
  I think the feature you need is [A 'contains' operation for the api to search multiselect custom values](https://issues.civicrm.org/jira/browse/CRM-17096), which is work in progress. See the associated [pull request #6612](https://github.com/civicrm/civicrm-core/pull/6612) for discussion of progress - it seems to have stalled but with good work already having been done.
  
  
  ---
  
  ### Answer by username_2 on 2017-03-10. Score: 0
  
  May be try the below - If the below doesn't help then you need to write a sql for the same I guess
  
  ```
  $result = civicrm_api3('Event', 'get', array(
    'sequential' => 1,
    'return' => array("custom_13"),
    'custom_13' => array('NOT IN' => array(2, 3)),
  ));
  
  ```
  
  try to set unwanted category in "NOT IN" condition
  
  Thanks - I guess this helps!!!
  
  > **Comments:**
  > **username_0**: Sorry, but you misunderstand my issue. It's ok, that the event is in category `2` or `3`, as long it is in `1`.  
  > **username_2**: did you try to run the same - this is giving you a list of category A from all the set -  
  > **username_0**: Oh, you seem to be right. But I don't understand why this works. Shouldn't 'NOT IN' exclude all events, that are in `2` or `3`, even though they are in `1`?  
  
  ---
  
  ### Answer by username_0 on 2018-02-08. Score: 0
  
  Because [#6612](https://github.com/civicrm/civicrm-core/pull/6612) has been closed I'm currently using `LIKE` as a workaround:
  
  ```
  CRM.api3('Event', 'get', {
    "sequential": 1,
    "custom_1": {"LIKE":"%category A%"}
  }).done(function(result) {
    // do something
  });
  
  ```
  
  which is working fine if the value is not part of another value. E.g filtering by "*category A*" would also list events of "*category A*wesome".
  
  
  ---
  
  