When I convert a lead to an opportunity I want to populate the Opportunity 'name' field automatically with salutionName + firstName + lastName from the lead fields, I'm fumbling around trying to cobble together some code for a custom hook but all totally new to me so if anyone can help I'd appreciate it, is this code along the right lines? It doesn't seem to work
	
							
						
					PHP Code:
	
namespace Espo\Custom\Hooks\Lead;
use Espo\ORM\Entity;
class Lead_To_Opportunity_Hook extends \Espo\Core\Hooks\Base
public function beforeSave(Entity $entity, array $options=array())
{
    $entityManager = $this->getEntityManager();
    $sisterId = $entity->get('opportunityId');
    $sisterType = 'Opportunity';
    $sisterObject = $entityManager->getRepository($sisterType)->where(['id'=>$sisterId])->findOne();
    // Pass Lead salutation, first name and last name to Opportunity name field
    $opportunityName = $entity->get('salutationName').' '.$entity->get('firstName').' '.$entity->get('lastName');
    $sisterObject->set('name',$opportunityName);
    $entityManager->saveEntity($sisterObject);
} 

Comment