Setting New Opportunity Revenue Line Item Assigned To and Teams

When creating a new Opportunity (Opp), the Revenue Line Item (RLI) is also created at the same time. Currently, the RLI Assigned To and Teams are set to the values of the person creating the records, but we would like the RLI Assigned To and Teams to be equal to the Opportunity Assigned To and Teams. We'd only like this on initial RLI Creation because we'd like to have the ability to change it and make it different, if needed, later. 

I was thinking of a SugarBPM process initiated on a new RLI Record Creation, but I can't seem to find the right way to set the RLI Assigned To and Teams fields to the values in the Opportunity. 

Maybe there's an entirely different way to do this, but we are new at Sugar and haven't done much in the customization way other than some SugarLogic formulas for fields and very rudimentary SugarBPM processes. 

Thanks for any help!

Parents
  • As Adam said it is not possible to configure that via Sugar BPM, instead you may create a Dependency SetValue in order to populate team_id, team_set_id and assigned_user_id on RLI as per respective values on Opportunity. Under a Dependency you can even choose to trigger such action only on creating a RLI, that means, when its ID is empty.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Sounds promising. Is there some documentation on how to develop and deploy a Dependency SetValue? Sort of sounds like SugarLogic, but I'm still learning here. Thanks for the help!

  • If there are more customizations, or if you're looking at coding anyways, another option is to use logic_hooks. Just leaving it here in case it helps you/others:

    <?php
    
    class CopyTeamAssignedUserHook
    {
        function execute($bean, $event, $arguments)
        {
            if (empty($bean->fetched_row) &&    // Do this only for new records
                !empty($bean->opportunity_id))  // Ensure there is an opportunity
            {
                $opportunity = BeanFactory::getBean('Opportunities', $bean->opportunity_id);
                $bean->assigned_user_id = $opportunity->assigned_user_id;
                $bean->team_id = $opportunity->team_id;
                $bean->team_set_id = $opportunity->team_set_id;
            }
        }
    }  

    This logic hook will go into the RevenueLineItems module, as you know already.

    This link explains how to install logic hooks for packages:https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/

Reply Children
  • I took a shot at building the installable package for the above customization. If someone had a chance to review it, as this is the first I've built, that would be awesome. I took the structure of the package from the Creating an Installable Package for a Logic Hook > https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Cookbook/Module_Loadable_Packages/Creating_an_Installable_Package_for_a_Logic_Hook/ 

    rli_copy_opportunity_team_assigned_logic_hook.zip

  • Hi Vince,

    After having a quick glance I believe you are good to deploy and test it. Please upload the zip package in sandbox environment, test and move ahead. :)

  • Hi Vince, 

    just to make it simple: The MAC is a big messi when it comes to creation of zip-files.

    1st, your zip file must have the manifest.php and the Files directory in the root directory. In your file you find the directory rli_copy_opportunity_team_assigned_logic_hook and the typical MAC garbage __MACOS. 

    2nd there is a file .DS_store in nearly each directory, again MAC garbage which must be removed.

    3rd: A LICENSE file should be added, even if it contains only empty lines.

    When you zip your installable it should contain the following files and nothing else:

    Related to the manifest file, I would use 

    'acceptable_sugar_versions' => array('9.*.*','10.*.*'),

    which is not the univeral unlocker like the regex. RLIs exist not since the beginning of Sugar.

    SugarFlavor CE will not work witj RLIs and is not supported any more.

    Lastly, your name is very long, This name is used to create some file names during installation. So it could happen, if the file system of the target machine has issues with long filenames (like Windows has), your function will be installed but will not run correctly.

    I always use the same strings for name and id and try to make them short and simple.

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • FYI this is the command i use to zip my files on a Mac and avoid including the system-generated files:

  • From Manipulating Teams PRogrammatically > https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Architecture/Teams/Manipulating_Teams_Programmatically/

    It doesn't seem like you set the Teams by just setting the team_set_id as in the great example above, but you need to set individual Team IDs via the replace() method. Is there a way to set the whole RLI "replace" array with something from the Opportunity team set? Thanks in advance for helping me rationalize the example above with the Manipulating Teams Programmatically code!  VO

  • Hi Vince!  Nice way to put up the question there  Joy 

    If you want to follow the programmatic way, you can create an after save logic hook as mentioned in the documentation - and you can replace the teams in Line Items something like:

    // Set Opportunity's teams in Line Items
    $teamSetBean = new TeamSet();
    $bean->load_relationship('teams');
    $bean->teams->setSaved(false); // Manually reset TeamSet state for save
    $opportunityTeamIds = $teamSetBean->getTeamIds($opportunity->team_set_id);

    // Set Teamset
    $bean->teams->replace($opportunityTeamIds);

    // Set Primary Team
    $bean->team_id = $opportunity->team_id;
  • Thanks Neeraja! You have been a great help!

    I believe I needed to add the step to get the bean for $opportunity before it could be referenced. 

    I tested the following out and the RLI continues to have both the Teams from the Opportunity, plus any additional Default Teams from the user creating the RLI. So I'm trying to figure that out now. It seems like the RLI Teams need to be "removed" or emptied out before they are replaced with the Opportunity's Teams. 

    <?php

    class CopyTeamAssignedTo
    {
    function execute($bean, $event, $arguments)
    {
    if (empty($bean->fetched_row) && // Do this only for new records
    !empty($bean->opportunity_id)) // Ensure there is an opportunity
    {
    // Get / Set Opportunity
    $opportunity = BeanFactory::getBean('Opportunities', $bean->opportunity_id);

    // Set Opportunity's teams in Line Items
    $teamSetBean = new TeamSet();
    $bean->load_relationship('teams');
    $bean->teams->setSaved(false); // Manually reset TeamSet state for save
    $opportunityTeamIds = $teamSetBean->getTeamIds($opportunity->team_set_id);

    // Set Teamset
    $bean->teams->replace($opportunityTeamIds);

    // Set Primary Team
    $bean->team_id = $opportunity->team_id;
    }
    }
    }

  • RLI continues to have both the Teams from the Opportunity, plus any additional Default Teams from the user creating the RLI

    Hi Vince,

    Appreciate your patience and effort in trying to get this code work.

    I noticed that I sent the code in a hurry without testing, my bad. The reason why the original team is still attached is because of the order of setting team_id and teams. The team_id should be set first, so that it doesn't get added during replace. I also removed the "teams->setSaved(false)", since you're probably using this in a before_save hook.

    This version should work, please try it out: