Announcement

Collapse
No announcement yet.

Espo 5.2.x auto-increment value in hooks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • murray99
    replied
    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.

    Leave a comment:


  • umar
    replied
    tanya did you get a chance to check this ?

    Leave a comment:


  • umar
    commented on 's reply
    $entity->get('number') this number field is the one with type auto-increment.

  • umar
    replied
    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:


  • tanya
    replied
    After save entity has this field.

    share with me your code, please

    Leave a comment:


  • umar
    replied
    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:


  • tanya
    replied
    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:


  • cavefish
    started a topic Espo 5.2.x auto-increment value in hooks

    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?

    Thanks
Working...
X