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/

  • 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;
    }
    }
    }

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?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);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Reply
  • 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;
    }
    }
    }

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?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);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Children
  • 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:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?php
    /**
    * Replaces Line Item teams from Opportunity
    *
    * Class CopyTeamAssignedTo
    */
    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');
    $opportunityTeamIds = $teamSetBean->getTeamIds($opportunity->team_set_id);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX