2

In my project I am using a scheduled job to get street recruitment data from a csv file and create a new membership with the API if required. When the membership is created, an activitiy is also automatically created using the logged in user as the activity source contact. Does anyone know if I can influence this activity source contact with the API? My workaround is changing the activity once it is generated with the post hook. Works, but is a bit hackish :-)

2
  • 1
    ErikH, interesting question, can you add the activities tag to it? Commented Aug 3, 2015 at 19:40
  • I added the tag. Commented Aug 3, 2015 at 20:07

1 Answer 1

3

At this point, no, at least as long as you aren't using the API as the member him/herself. The relevant line is https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Activity/BAO/Activity.php#L1886:

// create activity with target contacts
$session = CRM_Core_Session::singleton();
$id = $session->get('userID');
if ($id) {
  $activityParams['source_contact_id'] = $id;
  $activityParams['target_contact_id'][] = $activity->contact_id;
}

Basically, CRM_Member_BAO_Membership::create calls CRM_Activity_BAO_Activity::addActivity, and the code above just forces the source contact to be whoever's logged-in.

Ironically, just a few lines above, the activity source contact is set to be the ID set in the contact_id property of the activity object passed to the function from the membership, but this overrides it.

1
  • Thanks @Andrew, and ironically indeed :-) I'll just go with my workaround. Commented Aug 4, 2015 at 6:37

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.