AnsweredAssumed Answered

Need help adding line to logic hook that will copy all data to a new module

Question asked by Jake Ashley on Aug 8, 2019
Latest reply on Aug 12, 2019 by Ashish Dwivedi

Sugar OnDemand 9.1.0 Professional

 

When an opportunity reaches a sales stage of Closed Won, we create an account record in the Accounts module. The below works as intended in that respect, but I want to ensure that all data from the Opportunity record is copied over to the new account record and then deletes the opportunity record. Can you help me achieve this?

 

<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class CreateAccountHook
{

    function after_save_method($bean, $event, $arguments)
    {
        //check if a fields value has changed
        if(isset($arguments['dataChanges']['sales_stage']) && $bean->sales_stage=='Closed Won')
        {
               $newAcc = BeanFactory::newBean('Accounts');
            $newAcc->name = $bean->name;
            $newAcc->save();
        }
    }
}

?>

Outcomes