diff --git a/application/Espo/Core/Formula/Functions/RecordServiceGroup/ThrowDuplicateConflictType.php b/application/Espo/Core/Formula/Functions/RecordServiceGroup/ThrowDuplicateConflictType.php index f41aafa71d..67a965c25f 100644 --- a/application/Espo/Core/Formula/Functions/RecordServiceGroup/ThrowDuplicateConflictType.php +++ b/application/Espo/Core/Formula/Functions/RecordServiceGroup/ThrowDuplicateConflictType.php @@ -31,15 +31,20 @@ namespace Espo\Core\Formula\Functions\RecordServiceGroup; use Espo\Core\Di\EntityManagerAware; use Espo\Core\Di\EntityManagerSetter; +use Espo\Core\Di\RecordServiceContainerAware; +use Espo\Core\Di\RecordServiceContainerSetter; use Espo\Core\Exceptions\Conflict; use Espo\Core\Exceptions\ConflictSilent; use Espo\Core\Formula\ArgumentList; use Espo\Core\Formula\Functions\BaseFunction; use Espo\Core\Utils\Json; -class ThrowDuplicateConflictType extends BaseFunction implements EntityManagerAware +class ThrowDuplicateConflictType extends BaseFunction implements + EntityManagerAware, + RecordServiceContainerAware { use EntityManagerSetter; + use RecordServiceContainerSetter; /** * @inheritDoc @@ -72,10 +77,16 @@ class ThrowDuplicateConflictType extends BaseFunction implements EntityManagerAw foreach ($ids as $id) { $entity = $this->entityManager->getEntityById($entityType, $id); - $name = $entity ? $entity->get('name') : $id; + if ($entity) { + $this->recordServiceContainer->get($entityType)->prepareEntityForOutput($entity); + } + if (!$entity) { + $entity = $this->entityManager->getNewEntity($entityType); + $entity->set('name', $id); + } - $list[] = (object) ['id' => $id, 'name' => $name]; + $list[] = $entity->getValueMap(); } throw ConflictSilent::createWithBody('duplicate', Json::encode($list)); diff --git a/application/Espo/Core/Record/Service.php b/application/Espo/Core/Record/Service.php index 6a2e4254b7..223076c104 100644 --- a/application/Espo/Core/Record/Service.php +++ b/application/Espo/Core/Record/Service.php @@ -564,22 +564,17 @@ class Service implements Crud, */ protected function processDuplicateCheck(Entity $entity): void { - $duplicateList = $this->findDuplicates($entity); + $duplicates = $this->findDuplicates($entity); - if (empty($duplicateList)) { + if (!$duplicates) { return; } - $list = []; - - foreach ($duplicateList as $e) { - $list[] = (object) [ - 'id' => $e->getId(), - 'name' => $e->get('name'), - ]; + foreach ($duplicates as $e) { + $this->prepareEntityForOutput($e); } - throw ConflictSilent::createWithBody('duplicate', Json::encode($list)); + throw ConflictSilent::createWithBody('duplicate', Json::encode($duplicates->getValueMapList())); } /**