Workflow Convert Opportunity to Project

Hi all

I have succesfully make a workflow that converts won opportunities to new projects. Iā€™ve managed to carry forward all the fields except for ā€˜contactā€™ explained further below.

There is no option to map the contact field in the workflow, has any one any ideas?

Thanks

Dan

The contact or contact(s) related to the Opportunity is not a field, its a relationship. If you want to carry the contacts related to the opportunity over to project you have to map the relationship. I donā€™t think you can do this through workflow. Iā€™ve always written a before save hook to map the contacts over. If you had a field in Opps like ā€œmain contactā€ and wanted to carry that over to Projects you could. Really what you want to do is write a hook that loops through the relationships of the Opportunity and then copies them over to the relationships of the project. ( think anyway unless someone has a better idea).

Hi,

Thank you for your reply. I thoughtthat might be the case, I made the relationship but it doesnā€™t want to work. So I thought it might come down to a hook, unfortunately thats really not my field of expertise. Iā€™ll reach out to a dev I use and see what they can do.

Thank you

Dan

Hereā€™s what I use for my clients. Typically Iā€™m copying custom relationships over on convert. But this could be adapted to your situation. You could customize the ā€œifā€ condition for example to opportunity = won or somethingā€¦

In the example heā€™s copying over notes, but it could be modified to copy over contacts.

Hereā€™s how Iā€™ve used it for contacts:

<?php

/*************************************
Project: Relation Transfer
Original Dev: Angel MagaƱa, March 2012
@2012 Angel MagaƱa
cheleguanaco[at]cheleguanaco.com

Desc: Logic Hook for Transferring Relation

The contents of this file are governed by the GNU General Public License (GPL).
A copy of said license is available here: http://www.gnu.org/copyleft/gpl.html
This code is provided AS IS and WITHOUT WARRANTY OF ANY KIND.
*************************************/

class DataTransfer
{
 function doDataTransfer($bean, $events, $arguments)
 {
  $action  = $_REQUEST['action'];
  
  if ($action == 'ConvertLead') //Must confirm it only triggers on conversion!!
  {
   $lead_id  = $bean->id;
   $contact_id = $bean->contact_id;
    
   $bean->load_relationship('leads_contacts_1');
   
   //Remove relationship 
   $rcontacts = array();
   foreach ($bean->leads_contacts_1->getBeans() as $rcontact)
   {
    $rcontact_id = $rcontact->id;
    $rcontacts[] = $rcontact_id;   
   
    $bean->leads_contacts_1->delete($lead_id, $rcontact_id);
   }
  
     
   //Transfer relationship to Contact record
   $contact = new Contact();
   $contact->retrieve($contact_id);
   
   $contact->load_relationship('contacts_contacts_1');
   foreach ($rcontacts as $rcontact)
   {
    $contact->contacts_contacts_1->add($rcontact);
   }
  }
 }
}

?>

1 Like

Thatā€™s great thank you Iā€™ll have a go