2

I'm looking to swap out the hashed ID for the case ID in Case emails (now that email processing works for this and you can search by case id.)

I've looked through the two related posts here on stack and the issue on JIRA but can't find specifics.

I can adjust the Cases - Send Copy of an Activity template but that only affects copies of any activity sent, NOT emails that are sent. (In case it's helpful to anyone finding this post - the token is {$caseID}.)

In this post answer Demerit says "we removed the hash and just use the actual case id by editing the civimail template" but I've not had any luck yet with the one case template there is.

(Civi 5.5.3)

2 Answers 2

2

For Emails sent from Manage Case to case roles, there is hook_civicrm_alterMailParams that can be used to alter the subject. Here's some (maybe-not-the-greatest) code I have from an earlier customization. Note that the logic here will remove the hash whether it actually finds the case or not, which was desirable at the time but in those weird scenarios you might prefer it to leave the hash, in which case just move that part down inside the if ($case_id) block.

function myextension_civicrm_alterMailParams( &$params )
{
    if (preg_match('/\[case #([0-9a-h]{7})\]/', $params['subject'], $matches)) {
        $key = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY);
        $hash = $matches[1];
        $sqlParams = array(1 => array($hash, 'String'));
        $case_id = null;
        $dao = CRM_Core_DAO::executeQuery("SELECT id FROM civicrm_case WHERE SUBSTR(SHA1(CONCAT('$key', id)), 1, 7) = %1", $sqlParams);
        if ($dao->fetch()) {
            $case_id = $dao->id;
        }
        $dao->free();

        // remove the case # part - can't do it through message templates since hardcoded in Contact/Form/Task/EmailCommon.php. Note also Activity/BAO/Activity.php removes it before saving on the case but that's after it sends it.
        $pos = strpos( $params['subject'] , '] ' );
        if ( $pos !== FALSE ) {
            $params['subject'] = substr( $params['subject'], $pos + 2 );
        }

        // Now add the real case id if found
        if ($case_id) {
            $params['subject'] .= " [case #{$case_id}]";
        }
    }
}
0
2

There's now an extension for this, with a couple additional features: https://lab.civicrm.org/extensions/caseidinsubject

1
  • Awesome. I'll get to testing and implementing that!!
    – RayWright
    Commented Aug 4, 2020 at 14:36

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.