one default assigned user across all entities

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1602

    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.
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #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.
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    Working...