How to add records to a new entity in AfterInstall script of an extension

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ednt
    Member
    • May 2022
    • 37

    How to add records to a new entity in AfterInstall script of an extension

    Hi,

    I want to build an own extension and I need to prefill 2 tables.
    I thought the right place is in AfterInstall.php
    I wrote a php loop with fgetcsv() and get the records.
    But I don't know how to add these records to the new entity.
    I tried it with $entity->set() but this looks wrong.

    How can I add records in AfterInstall.php ?

    Best regards,

    Bernd
  • yuri
    Member
    • Mar 2014
    • 8807

    #2
    Hi Bernd,

    The container is passed to the 'run' method.

    PHP Code:

        
    public function run(\Espo\Core\Container $container$params = [])
        {
            
    $em $container->getByClass(\Espo\ORM\EntityManager::class);
      
            
    // Check whether records do not already exist. Then, create.
        

    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...