I created a custom field set with three fields, the field set does allow multiple records. The aim of this field set is to collect data about candidacies and mandates of politicians, such as the parliament name, the party/ fraction and the election result. One politician can have more than one of these.

I now want to update a specific record when it exists. I find out by calling the API:

   $result = civicrm_api3('Contact', 'get', [
      'sequential' => 1,
      'return' => ["custom_102", "custom_101", "custom_103"],
      CiviCRMFields::CANDIDACY_MANDATE_ID  => $id

This only returns the contact when the contact has a candidacy/ mandate record with id $id. When I then set the fields "custom_102", "custom_101" or "custom_103" with the new data, a new record is created:

 $result = civicrm_api3('Contact', 'create', $this->contactValues);

where $this->contactValues includes all the values returned by the preceding API call. As these values include the id of the record in the field set table I thought it would be clear that this record needs an update but CiviCRM keeps creating additional new records.

How can I update this specific record???

Best, Tobias

Your Answer

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

Browse other questions tagged or ask your own question.