Announcement

Collapse
No announcement yet.

Cloning entity Opportunity to new one

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

  • Cloning entity Opportunity to new one

    Hello community. I am pretty new in Espo CRM, but i like it so much!

    I found similar topics and tutorials related to this but looks like all of these solutions are outdated.. Would be great if someone can help me and also to others interested..

    As title says i want to clone Opportunity to new one entity etc called ( Production ) which will share whole functionality of Opportunity.

    Description of my requierements:

    I have 5 phases in Opportunity and i would like to create clone of Opportunity where will be automatically ( in worse case also manually from admin panel ) added only all records which are already in Opportunity Phase 4.
    So my new entity ( Production ) get all records from Opportunity Phase 4 and they will be added to Production Phase 1.
    Then i create more unique phases for entity Production, add new fields and will be able to move to next Phase and display different info in Kanban etc.
    Is something like this possible? Or what is the best way how to solve this need please?

    Thanks a lot!


  • #2
    If you not familiar with php use AdvancedPack
    Define workflow or business process trigerred with three paramaters:
    updated
    status field changed
    status field = Phase 4
    and then create record with all desired fields and values

    If you familiar with php you can define hook and create all the steps in it.

    Comment


    • fenolghi
      fenolghi commented
      Editing a comment
      Hello thank you, i am pretty familiar with PHP i just do not know EspoCRM well and many tutorials what i found is just outdated.. Going to check how hooks works, thanks for your help, please if there is any tutorial or documentation, be so kind and pin it to me, i am glad for everything what can help me..

      Found this: https://docs.espocrm.com/development/hooks/

  • #3
    Hello Espo community! Can someone help me to modify my hook?
    I am creating duplicate records in new entity "Production" from specific records stored in Opportunity. I created same fields in both entities and i am successfully able to copy
    text fields, email field and so..
    This part works well, but i am not able to copy and share fields as "file, image, multifield"
    These fields in records in new entity "Production" are empty. Can someone help me how to set these types of field to my hook? ( names are same in both entities )

    Here is my AFTERSAVE hook

    PHP Code:
    <?php

    namespace Espo\Custom\Hooks\Opportunity;

    use 
    Espo\ORM\Entity;

    class 
    AfterSave extends \Espo\Core\Hooks\Base
    {
        public function 
    afterSave(Entity $entity, array $options)
        {
            if (
    $entity->has('duplirealizacie') && $entity->get('duplirealizacie')) {
                
    $entityManager $this->getEntityManager();

                
    $production $entityManager->getRepository('Production')->where([
                    
    'oppid' => $entity->get('oppid')
                ])->
    findOne();

                if (!
    $production) {
                    
    $production $entityManager->getEntity('Production');
                }

                
    $production->set([
                    
    'name' => $entity->get('name'),
                    
    'customerId' => $entity->get('accountId'),
                    
    'oppid' => $entity->get('oppid'),  //autoincrement field
                    
    'description' => $entity->get('description'),
                    
    'emailAddress' => $entity->get('emailAddress'),
                    
    'somefilefield' => $entity->get('somefilefield'),  // etc file or image or multifield does not work by this way
                    
    'amount' => $entity->get('amount')
                ]);
               
    // picpic is name of image field, this one does not work
                
    if ($entity->has('picpic') && $entity->get('picpic')) {
                    
    $picpicValue $entity->get('picpic');
                    
    $production->set('picpic_id'is_array($picpicValue) ? reset($picpicValue) : $picpicValue);
                }

                
    $production->set('opportunity_id'$entity->get('id'));

                
    $entityManager->saveEntity($production);
            }
        }
    }
    Thank you so much for help!
    Last edited by fenolghi; 11-26-2024, 03:18 AM.

    Comment

    Working...
    X