1

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."?

2

I think the feature you need is A 'contains' operation for the api to search multiselect custom values, which is work in progress. See the associated pull request #6612 for discussion of progress - it seems to have stalled but with good work already having been done.

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!!!

  • Sorry, but you misunderstand my issue. It's ok, that the event is in category 2 or 3, as long it is in 1. – Philipp Michael Mar 10 '17 at 9:45
  • did you try to run the same - this is giving you a list of category A from all the set - – Ramesh - ARTECH Consultancy Mar 10 '17 at 9:47
  • 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? – Philipp Michael Mar 10 '17 at 12:39
0

Because #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 Awesome".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.