Announcement

Collapse
No announcement yet.

Espo 5.2.x auto-increment value in hooks

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

  • 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

  • #2
    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

    Comment


    • #3
      hi tanya, can you please provide a bit more detail, how to load this entity, and get the value in afterSave hook.

      Comment


      • #4
        After save entity has this field.

        share with me your code, please

        Comment


        • #5
          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();
          }
          }

          Comment


          • umar
            umar commented
            Editing a comment
            $entity->get('number') this number field is the one with type auto-increment.

        • #6
          tanya did you get a chance to check this ?

          Comment


          • #7
            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.

            Comment

            Working...
            X