Our users are creating many new Activities which are Assigned To the user creating the Activity. I want to save them time and keystrokes by having Assigned To: default to that logged-in user's name. How can I do this? Thanks.


Create a simple extension implementing hook_civicrm_buildForm like so:

function myextension_civicrm_buildForm($formName, &$form) {
  if ($formName == 'CRM_Activity_Form_Activity' && $form->getAction() == CRM_Core_Action::ADD) {
    $form->setDefaults(array('assignee_contact_id' => $form->_currentUserId));
  • Great Coleman, thanks so much. Will try creating it tonight. Aug 3 '15 at 21:18
  • 'action' needs to be changed to 'getaction'. In other words, $form->action needs to be $form->getaction otherwise it throws an error.
    – OregonJohn
    Aug 18 '15 at 8:13
  • Well I got you pretty close anyway. Have updated the answer (you can edit answers too!)
    – Coleman
    Aug 18 '15 at 12:38

You can (must) use an extension.

You can either use hook_buildForm to include a jQuery snippet that looks up the current user and populates the field, or you can use hook_post to do the same if there's no "Assigned to" set. The first approach lets the user see the "Assigned To" with their name, but the second approach covers activities created via other means than the "New Activity" form (import, API, profiles, etc.). If you go the second route, you need to make sure it's not assigning activities automatically for people contributing online etc.!

  • Jon G, thanks, so I'm writing a new extension to do this, right. Seems like hook_buildForm is the much safer route for my needs. Thanks so much. Aug 3 '15 at 20:27
  • 1
    I don't think you'll need jQuery. See my answer for example code.
    – Coleman
    Aug 3 '15 at 20:32

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.