I'm setting up CiviCase with a new case type of 'Press Release'. We only have one press officer, but want other staff (those who more often deal directly with our members) to be able to open cases. So I wanted a case role of 'Press Officer', as the case manager, automatically given to a particular cid for all cases of that type.

My first thought for this was a post hook, but when you create a case, what you get in the post hook has no client contact IDs set yet. (This isn't a case of CRM-15914, it's not there if I do an explicit Case.get on that case ID either.) The problem is, clients are added to the case (inserted into civicrm_case_contact) only after the post hook is fired for the case creation, and adding a client has no hooks of its own.

How can I automatically assign a role to someone other than the creator when a case is created?

3 Answers 3


The post hook does not perform as expected for cases :-) I have done some mods to do exactly what you are doing: automatically assigning a role. I have done this in 2 ways:

  1. using the post hook on the Activity Open Case
  2. using the caseSummary hook and checking if there is no other activity than Open Case. In this case I still allow the user to override what I have done as it would then have more activities than just Open Case

A refactor of CiviCRM Case is still on my wish list :-)

  • Good idea on the 'Open Case' one. The case probably has the clients associated with it by then? (I'm just looking at the case API code, it creates the case, then adds the contacts, then processes the XML configuration which is where the activity timeline lives)
    – DaveFF
    Commented Dec 14, 2015 at 16:28
  • Yes, all the Case stuff is then completed. The client is there, the relationship with the case coordinator etc. Commented Dec 14, 2015 at 16:34

How I solved this was to bring CRM_Case_BAO_Case into custom PHP, and basically copy the firing of the hooks from create() to addCaseToContact(), changing the entity type to the new 'CaseContact'.

Now the adding of a contact to a case fires a hook, that I can catch to create the relationship for a case role. It even works for cases with multiple clients, if you have this enabled.

Would pre/post hooks for adding a contact to a case be a useful thing to have in core?


You can use the postprocess hook and check for CRM_Case_Form_Case. I did have some trouble finding the case id though, but maybe I'm just not seeing it. A "bad" workaround would be to assume the case id is the latest one just created in the database, unless it's a busy site.

  • You can indeed. In my case the stuff could also come via the API using Webforms, so the postProcess was no joy for me :-) Commented Dec 14, 2015 at 16:35

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.