I am creating duplicate records in new entity "Production" from specific records stored in Opportunity. I created same fields in both entities and i am successfully able to copy
text fields, email field and so..
This part works well, but i am not able to copy and share fields as "file, image, multifield"
These fields in records in new entity "Production" are empty. Can someone help me how to set these types of field to my hook? ( names are same in both entities )
Here is my AFTERSAVE hook
PHP Code:
<?php
namespace Espo\Custom\Hooks\Opportunity;
use Espo\ORM\Entity;
class AfterSave extends \Espo\Core\Hooks\Base
{
public function afterSave(Entity $entity, array $options)
{
if ($entity->has('duplirealizacie') && $entity->get('duplirealizacie')) {
$entityManager = $this->getEntityManager();
$production = $entityManager->getRepository('Production')->where([
'oppid' => $entity->get('oppid')
])->findOne();
if (!$production) {
$production = $entityManager->getEntity('Production');
}
$production->set([
'name' => $entity->get('name'),
'customerId' => $entity->get('accountId'),
'oppid' => $entity->get('oppid'), //autoincrement field
'description' => $entity->get('description'),
'emailAddress' => $entity->get('emailAddress'),
'somefilefield' => $entity->get('somefilefield'), // etc file or image or multifield does not work by this way
'amount' => $entity->get('amount')
]);
// picpic is name of image field, this one does not work
if ($entity->has('picpic') && $entity->get('picpic')) {
$picpicValue = $entity->get('picpic');
$production->set('picpic_id', is_array($picpicValue) ? reset($picpicValue) : $picpicValue);
}
$production->set('opportunity_id', $entity->get('id'));
$entityManager->saveEntity($production);
}
}
}
Leave a comment: