1

Been playing with the API and see how to query for a result set but not the appropriate way to get a result set and update it batch style(over 4000 contacts in this case).

My goal is to gather all contacts with an empty custom field value and copy the text value for 'current employer' into that field.

This is in php using the 'class.api.php'. If there is a more appropriate way to achieve this I am open to suggestions.

1 Answer 1

2

I think you can use chain api to do this. Try using below snippet

$result = civicrm_api3('Contact', 'get', [
  'sequential' => 1,
  'return' => ["current_employer_id"],
  'custom_1' => ['IS NULL' => 1],
  'employer_id' => ['IS NOT NULL' => 1],
  'api.Contact.create' => [
    'id' => "\$value.id", 
    'custom_1' => "\$value.current_employer_id"
  ],
]);

(Replace custom_1 with custom field id from your system.)

HTH

Pradeep

Your Answer

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

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