AnsweredAssumed Answered

Retrieve emails belonging to a case

Question asked by dnolan dnolan on Oct 8, 2015
Latest reply on Apr 22, 2016 by Aremu Habibullahi

I'm automatically creating Cases from inbound Emails.

The Email gets synced, the Case created, and a link is made between the two.

In the 'after_save' logic hook of a Case, I have it set up so that an email is sent to the Case owner, and I use the email sender's address as the reply-to.  

If the case has been related to a Contact, it grabs the email from the Contact bean.
If the case has no Contact associated, it should have an Email, so grab email from an email bean.

So, after_save

        if ($caseBean->load_relationship('contacts')) {


                //Fetch related beans

                $contactBean = $caseBean->contacts->getBeans();


                if (!empty($contactBean)) {


                    $patientName  = $contactBean->name;


                    $patientEmail = $contactBean->email1;


                } else {


                    if ($caseBean->load_relationship('emails')) {


                        $emailBean = $caseBean->emails->getBeans();


                        if (!empty($emailBean)) {


                           //$patientEmail = $emailBean->emailAddress; //psuedo-code, this doesn't work









If a contact is associated, it grabs the email no problem.

However I have having a problem loading the relationship between the Case and Email beans.  the $emailBean is returning empty.

In short; How can I load a related Email bean from a Case bean to retrieve the Email's sender address?