Announcement

Collapse
No announcement yet.

one default assigned user across all entities

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

  • one default assigned user across all entities

    As written in the subject, is it possible to have a default user on creating a record across all entities?
    Ist it also possible for other values, which should be the same in all entities? Something like mass update, but for all entities in one step.

  • #2
    Hi shalmaxb
    yes you can do it with global hook (my skill back-end)


    PHP Code:
    <?php
    namespace Espo\Custom\Hooks\Common;

    use 
    Espo\ORM\Entity;
    use 
    Espo\ORM\EntityManager;

    class 
    AssignedUser
    {    
        public static 
    int $order 5;

        public function 
    __construct(
            private 
    EntityManager $em,
        ){}

        public function 
    beforeSave(Entity $entity, array $options): void
        
    {

            if ( 
    $entity->isNew() && $entity->hasAttribute'assignedUserId' ) )
            {
                
    $entity->set('assignedUserId''idOfAssignedUser' );
            }
        }
    }
    this sample is just for new entity, you can remove the if statement or adapt to your requirement

    Save this file to the path in doc with the name of file AssignedUser.php
    Last edited by item; 03-14-2024, 08:04 PM.

    Comment

    Working...
    X