0

I am using civicrm on drupal 7. I have configured my Civi instance to accept external REST API calls with authentication.

I want to get all the values from a set of custom fields associated with an organization sub-type.

I am making a call something like this:

$contacts = civicrm_api4('Contact', 'get', [
  'select' => [
    'id', 
    'display_name', 
    'my_custom_field_set.*',
  ],
  'join' => [
    ['my_custom_field_set AS my_custom_field_set', 'LEFT'],
  ],
  'where' => [
    ['my_custom_field_set.name', 'IS NOT NULL'], 
    ['contact_type', '=', 'Organization'], 
    ['contact_sub_type', '=', 'CLC'],
  ],
]);

This mostly works... except for 5 entries in my database that get skipped. The five failures are all part of another sub-type: ICT Program Client which has some other fields and relationships associated with it.

If I remove the sub-type CLC WHERE constraint it works. But I would prefer to understand why the presence of the other sub-type on a contact would make the query fail.

The 5 failures are definitely of sub-type CLC.

1 Answer 1

2

Can you try with a LIKE 'CLC' rather than '='? This might help as the contact_sub_types are stored with the weird CRM_Core_DAO::VALUE_SEPARATOR around the values?

2
  • That didn't work, but changing the constraint to "CONTAINS" worked! I guess CIVI must store sub-types as a list of some kind?
    – tanbog
    Jul 15, 2022 at 8:38
  • 1
    Yes, a contact can have more than 1 sub type and it is stored in 1 field with the mentioned CRM_Core_DAO::VALUE_SEPARATOR in between. Jul 15, 2022 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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