1

Happy to be told we are going about this wrong.

SCENARIO: Case Manager gets sent an email from an external source to their private/organisational email address.

They want to forward/resend to it gets stored on the Case.

Manager goes in to Civi (or Views in our case) searches the contact, finds the relevant case, then, as i understand things, they need to include a value in the email such as

[case #44fec3a]

where that value is the first 7 letters of a hashed value of the civicrm site-key plus the case id

And indeed this works, if I send an email to the 'inbound email processing email address' and have [case #44fec3a] it gets added to the Case. Wonderful.

But the Case Managers have no way of knowing what the hashed value should be - and we need to be able to show it on both the CiviCase page and in Views.

So do we need to find a way to 'present' this 7-character string on both the Case page, and pull it together in our Views?

Or does anyone have a simpler/better suggestion/solution?

1
  • My memory tells me the fact that it's a hash and not the case id itself was a communication misunderstanding during development. Making it use case id instead would be my vote (but still accept hash for backwards compatibility). I have some code for this but it's for v4.2 which I can post somewhere. If keeping hash you could use civicrm_hook_caseSummary to display the hash on Manage Case at least.
    – Demerit
    Nov 17, 2017 at 2:02

1 Answer 1

1

Here's the override code I've used to make it accept some variations of case id (with and without the word case, with and without the # sign) as well as hash, prioritizing the fanciest to the plainest. It looks like the original code hasn't changed since 4.2 so this should work against 4.7 too.

Create an override for CRM/Activity/BAO/Activity.php, and in lines 607 thru 622 replace it with this:

$matches = array();
$subj_to_match = CRM_Utils_Array::value('subject', $params);
if (preg_match('/\[case #([0-9a-h]{7})\]/', $subj_to_match, $matches)) {
  $key        = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY);
  $hash       = $matches[1];
  $query      = "SELECT id FROM civicrm_case WHERE SUBSTR(SHA1(CONCAT('$key', id)), 1, 7) = '$hash'";
} elseif (preg_match('/\[case #(\d+)\]/', $subj_to_match, $matches)) {
  $hash       = $matches[1];
  // this seems like an odd query but we are checking the id actually exists
  $query      = "SELECT id FROM civicrm_case WHERE id = '$hash'";
} elseif (preg_match('/\[#(\d+)\]/', $subj_to_match, $matches)) {
  // technically this is a subset of the one below, but keeping it allows a subject that had both and prioritize this one
  $hash       = $matches[1];
  $query      = "SELECT id FROM civicrm_case WHERE id = '$hash'";
} elseif (preg_match('/\[(\d+)\]/', $subj_to_match, $matches)) {
  $hash       = $matches[1];
  $query      = "SELECT id FROM civicrm_case WHERE id = '$hash'";
}
if (!empty($matches)) {
  $caseParams = array(
    'activity_id' => $activity->id,
    'case_id' => CRM_Core_DAO::singleValueQuery($query),
  );
  if ($caseParams['case_id']) {
    CRM_Case_BAO_Case::processCaseActivity($caseParams);
  }
  else {
    self::logActivityAction($activity, "unknown case hash encountered: $hash");
  }
}

One interesting side effect of this is that saving a non-case activity using the normal civi UI but putting [1234] in the subject will save it as a case activity on case 1234!

4
  • thanks. i would vote for the 'case id' being okay. need to rustle up some more opinions somehow
    – petednz - fuzion
    Nov 17, 2017 at 2:51
  • More inclined to only accept [case #1234] and not [#1234] OR [1234] in the subject. So, nice to have the first two conditions from the above code :-) Nov 17, 2017 at 3:08
  • would be happy to test the patch if you can raise a related JIRA or PR in core @Demerit. Nov 17, 2017 at 3:11
  • Thanks. issues.civicrm.org/jira/browse/CRM-21446 @jitendrapurohit
    – Demerit
    Nov 17, 2017 at 14:55

Your Answer

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

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