service/ contact.php
PHP Code:
<?php
namespace Espo\Custom\Services;
use Espo\ORM\{
Entity,
EntityManager,
ServiceFactory,
};
class Contact extends \Espo\Modules\Crm\Services\Contact
{
protected function contactFromParent(Entity $entity)
{
$em = $this->getEntityManager();
$contactId = $entity->id;
$parentAccountId = $entity->get('accountId');
$account = $em->getEntity('Account', $parentAccountId);
$contacts = $em->getRepository('Account')
->getRelation($account, 'contacts')
->order('name')
->find();
foreach ($contacts as $contact) {
$contactFromParentList[$contact->id]['name'] = $contact->get('name');
}
$parentContactJson = json_decode(json_encode($contactFromParentList, true));
$entity->set('parentContactJson',$parentContactJson );
}
public function loadAdditionalFields(Entity $entity)
{
parent::loadAdditionalFields($entity);
$this->contactFromParent($entity);
//$GLOBALS['log']->warning( $entity->get('calls' ) );
}
public function loadAdditionalFieldsForPdf(Entity $entity)
{
$this->loadAdditionalFields($entity);
}
}
entityDefs/contact :
important is jsonArray and notStorable .. other i don't know
PHP Code:
"parentContactJson": {
"type": "jsonArray",
"notStorable": true,
"layoutDetailDisabled": true,
"layoutFiltersDisabled": true,
"layoutListDisabled": true,
"reportDisabled": true
}
{{#each parentContactJson}}
{{name}}
{{/each}}
Please choose better "word" for field
Leave a comment: