1

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

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}]";
        }
    }
}

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.