Hello, I am extending the class CaseObj to make sure that upon receiving an email the subject of the email is taken and, through an explode, you go to populate the fields of the Case.
My code is:
Log:
I think the problem is that the CaseObj class has no relationship with the Email entity, I just don’t know how to connect them.
Can someone help me?
Thank you
My code is:
PHP Code:
namespace Espo\Modules\MyModule\Repositories;
class CaseObj extends \Espo\Modules\Crm\Repositories\CaseObj
{
protected function beforeSave(Entity $entity, array $options = array())
{
parent::beforeSave($entity, $options);
try {
if ($entity->get('inboundEmailId'))
{
$GLOBALS['log']->error('------------ENTITY GET ID---------------------beforeSave '.$entity->get('id'));
$email = $this->getEntityManager()
->getRepository('Email')
->select(['id'])
->where(array(
'emailId'=> $email,
'parentType=' => 'Case',
'parentId=' => $entity->get('id')
))->findOne();
$GLOBALS['log']->error('------------EMAIL ID---------------------beforeSave '.$email->get('id'));
if($email){
$subjectEmail = $email->get('name');
$GLOBALS['log']->error('------------EMAIL SUBJECT---------------------beforeSave '.$subjectEmail);
$array=explode("-", $subjectEmail);
$area=$array[0];
$areaD=$array[1];
$entity->set('area', $area);
$entity->set('areaD', $areaD);
$GLOBALS['log']->error('----------------------AREA------------------------------------------- $area = ' . $area);
$GLOBALS['log']->error('----------------------AREA D----------------------------------------' . $areaD);
$GLOBALS['log']->error('----------------------CASE AREA----------------------------------' . $entity->get('area'));
}
}
}catch(\Exception $error){
$GLOBALS['log']->error('------------ERROR---------------------beforeSave '.$error);
}
}
}
PHP Code:
ERROR: Repositories CaseObj ------------CASE accountProjectId ---------------------beforeSave accountProjectI= [] []
ERROR: Repositories CaseObj ------------CASE accountProjectId --------------------- [] []
ERROR: ------------ENTITY GET ID---------------------beforeSave 652667200066255d7 [] []
ERROR: InboundEmail 65046ca6562def3bb, after-fetch hook; 0 Call to a member function get() on null [] []
I think the problem is that the CaseObj class has no relationship with the Email entity, I just don’t know how to connect them.
Can someone help me?
Thank you
Comment