5

We use CiviCRM's import data functionality (and api-csv-import-gui) to import partner's contributions from CSV files. This is working great because the CSV columns can be mapped to CiviCRM fields via a graphical user interface.

However, we've recently had the need to preprocess one of these fields and transform their data on import. This process can't be done outside CiviCRM for security reasons.

Can I still use CiviCRM's point-and-click mapping functionality while being able to preprocess a specific CSV column in PHP? Unfortunately I can't just map the columns-fields in code because the CSV columns change.

3

One possibility could be importing the data as it is (maybe using a temporary field for that column) and use hook_civicrm_post() to manipulate the contribution just after creation:

function example_civicrm_post($op, $objectName, $objectId, &$objectRef) {

  if ($objectName == 'Contribution' && $op == 'create') {

    if (!empty($objectRef->temporary_field)) {

      // Preprocess field. FIXME: do some validation first.
      $objectRef->real_field = do_awesome_stuff($objectRef->temporary_field);

      // Clear temporary field.
      $objectRef->temporary_field = '';
    }
  }
}

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.