BPM - creating copy of same module

Every year, we create a renewal quote for customers.  When customers accept a quote (denoted by changing the quote stage), we'd like to use BPM to create a copy of the quote (and the quote line items) for next year.  Unfortunately, BPM only lets you create a "related" record.  Since we're triggering the activity on the "Quote" module, it does not appear in the choices.

If anyone can point us to documents/website/video that explains how to create a copy of the quote along with the quote line items, I would appreciate it very mch.

Thank you!

Parents
  • Hi Bob!

    We had a similar requirement for opportunities, and logic hooks are probably the best approach here, since this involves multiple modules (eg: Quotes, Line Items). Requires a bit of coding but it's simple. 

    Step 1: Create a logic hook, like in this example:

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Cookbook/Logic_Hooks/Comparing_Bean_Properties_Between_Logic_Hooks/`

    Eg:

    
    $hook_array['after_save'][] = Array(1,'Quote for Next Year','custom/modules/Quotes/CreateQuoteForNextYear.php', 'CreateQuoteForNextYear','execute',);
    

    Step 2: When the Quote stage is "Accepted", add logic to copy the Quote & line items for next year, by copying the current quote into the new quote object. Here is a rough script that does that, needs some fine tuning per your requirements:

    
    // Clone Quote
    $newQuote = clone $currentQuote;
    $newQuote->description = 'For Next Year';
    
    // Load existing product bundles
    $currentQuote->load_relationship('product_bundles');
    $currentProductBundles = $currentQuote->product_bundles->getBeans();
    
    foreach ($currentProductBundles as $currentBundle) {
        // Create new product bundle
        $newProductBundle = clone $currentBundle;
    
        // Create products
        $currentProducts = $currentBundle->get_products();
        foreach($currentProducts as $currentProduct) {
            $newProduct = clone $currentProduct;
            $newProductBundle->products->add($newProduct);
        }
    
        // Add the bundle to the quote
        $newQuote->product_bundles->add($newProductBundle);    
        
    }
    
    // Done!
    $newQuote->save();
    

    Step 3: If you're using cloud, you may want to create a package for deployment, please follow the steps as described in this sugar documentation: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.2/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/

    Blue heart from Seven Tunes Labs

Reply
  • Hi Bob!

    We had a similar requirement for opportunities, and logic hooks are probably the best approach here, since this involves multiple modules (eg: Quotes, Line Items). Requires a bit of coding but it's simple. 

    Step 1: Create a logic hook, like in this example:

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Cookbook/Logic_Hooks/Comparing_Bean_Properties_Between_Logic_Hooks/`

    Eg:

    
    $hook_array['after_save'][] = Array(1,'Quote for Next Year','custom/modules/Quotes/CreateQuoteForNextYear.php', 'CreateQuoteForNextYear','execute',);
    

    Step 2: When the Quote stage is "Accepted", add logic to copy the Quote & line items for next year, by copying the current quote into the new quote object. Here is a rough script that does that, needs some fine tuning per your requirements:

    
    // Clone Quote
    $newQuote = clone $currentQuote;
    $newQuote->description = 'For Next Year';
    
    // Load existing product bundles
    $currentQuote->load_relationship('product_bundles');
    $currentProductBundles = $currentQuote->product_bundles->getBeans();
    
    foreach ($currentProductBundles as $currentBundle) {
        // Create new product bundle
        $newProductBundle = clone $currentBundle;
    
        // Create products
        $currentProducts = $currentBundle->get_products();
        foreach($currentProducts as $currentProduct) {
            $newProduct = clone $currentProduct;
            $newProductBundle->products->add($newProduct);
        }
    
        // Add the bundle to the quote
        $newQuote->product_bundles->add($newProductBundle);    
        
    }
    
    // Done!
    $newQuote->save();
    

    Step 3: If you're using cloud, you may want to create a package for deployment, please follow the steps as described in this sugar documentation: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.2/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/

    Blue heart from Seven Tunes Labs

Children