Entering the Opportunity Role on the Lead

I want to put an "Opportunity Role" field on the Leads module that when the Lead is converted places the Role value in the opportunities_contacts relationship. Has anyone done this before? If not, any suggestions on the best way to go about it?

  • I have never tried it before, however I can suggest the following steps:

    • Create a dropdown on Leads with the same list behind the opportunities_contacts relationship (opportunity_relationship_type_dom)
    • Create a logic hook after_save on Opportunities which fill in the relationship the appropriate value from that custom field.
    André Lopes
    Lampada Global
    Skype: andre.lampada
  • I have not tried this and the code below is NOT tested, but, I would use an after_relationship_add logic hook.

    from Opportunities, when the Opportunity is related to a Lead:

    • fetch the Lead
    • find the contact_id on the Lead (this will be the Contact that the Lead was Converted to)
    • find the contact role that you set in the dropdown on the Lead
    • update the role:
      • $oppBean->contacts->add($contact_id, array('contact_role' => $contact_role));

    So your after_relationship_add logic hook in Opportunities will look something like:

    function updateContactRole ($bean,$event,$arguments){
        if($arguments['related_module'] == 'Leads'){
            $leadBean = BeanFactory::retrieveBean('Leads',  $arguments['related_id']);
            if(!empty($leadBean)){
                if(!empty($leadBean->contact_id) && !empty($leadBean->contact_role_c)){
                    $contact_role = $leadBean->contact_role_c; //get the contact role from your Lead
                    $contact_id = $leadBean->contact_id;  //get the contact_id
                    //set the contact role on the Opportunity Contact relationship
                    $bean->contacts->add($contact_id, array('contact_role' => $contact_role));
                }
            }
        }
    }    

     

  • Hey  ,

    What's the business reason behind your request? Reporting? Tracking changes? Workflows? All of them?

    I ask because over the years I found the relationship attributes in Sugar ineffective for several reasons, including the fact that it is not easy to get that information back out of the system (reporting) or even act on it (workflows etc) and because you can only change/add relationship attributes AFTER the relationship has been created as a second step/save for the user.

    If you need to store more information on the relationship between two objects (whatever they are), I would recommend creating a module and two relationships for that. Then, to reduce users' burden, you could help them populate the relationship with the correct information with custom functionality (UI, backend and/or a combination). This approach would allow you reporting, workflow capability and changelog.

    For example, to track employment history between Accounts and Contacts, that's normally architected in Sugar through a joining module and 2 1-m relationships. And you could populate a record on this new module, every time a person changes account, together with start-end dates, title etc.

    Perhaps something similar might suit you best?

    Cheers

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States