diff --git a/application/Espo/Modules/Crm/Repositories/Task.php b/application/Espo/Modules/Crm/Repositories/Task.php index d970e3c5db..74abd33d8d 100644 --- a/application/Espo/Modules/Crm/Repositories/Task.php +++ b/application/Espo/Modules/Crm/Repositories/Task.php @@ -64,12 +64,15 @@ class Task extends \Espo\Core\Repositories\Event if ($parentId && $parentType) { if ($this->getEntityManager()->hasRepository($parentType)) { $columnList = ['id', 'name']; + if ($this->getEntityManager()->getMetadata()->get($parentType, ['fields', 'accountId'])) { $columnList[] = 'accountId'; } + if ($this->getEntityManager()->getMetadata()->get($parentType, ['fields', 'contactId'])) { $columnList[] = 'contactId'; } + if ($parentType === 'Lead') { $columnList[] = 'status'; $columnList[] = 'createdAccountId'; @@ -77,7 +80,12 @@ class Task extends \Espo\Core\Repositories\Event $columnList[] = 'createdContactId'; $columnList[] = 'createdContactName'; } - $parent = $this->getEntityManager()->getRepository($parentType)->select($columnList)->get($parentId); + + $parent = $this->getEntityManager() + ->getRepository($parentType) + ->select($columnList) + ->where(['id' => $parentId]) + ->findOne(); } }