Announcement
Collapse
No announcement yet.
Espo 5.2.x auto-increment value in hooks
Collapse
X
-
very late on, but Auto Increment does not seem to be set in an Entity event afterSave and so I had to check if it was null and then re-load from the database if it was in order to use an auto-increment in a hook.
-
public function afterSave(Entity $entity, array $options = array()){
if(empty($entity->get('serialNumber'))){
$prefix = "Test-";
$user = $this->getEntityManager()->getRepository('User')->get($entity->get('assignedUserId'));
if(!empty($user->get('name'))){
$prefix .= $user->get('firstName')[0].$user->get('lastName')[0]."-".$entity->get('number');
}
$pdo = $this->getEntityManager()->getPDO();
$sql = "update test set serial_number = '{$prefix}'";
$sth = $pdo->prepare($sql);
$sth->execute();
}
}
Leave a comment:
-
After save entity has this field.
share with me your code, please
Leave a comment:
-
hi tanya, can you please provide a bit more detail, how to load this entity, and get the value in afterSave hook.
Leave a comment:
-
in beforeSave hook it coudn't be possible, in afterSave it possible. Even if field is not set, you can load this entity with this field
Leave a comment:
-
Espo 5.2.x auto-increment value in hooks
Since version 5.2 I'm unable to get value of auto-increment fields in beforeSave() and afterSave() hooks on first save. Editing existing entries works fine.
Is there some kind of fundamental change regarding auto-increment fields since this version or am I doing something wrong?
ThanksTags: None
Leave a comment: