1
votes

So here is the scenario, I have a 1:N relationship between Opportunity entity and a custom entity called Split Percentage. Usually the owner of an opportunity is the 100% owner of the Revenue from the opportunity. In reality, you may have more than one sales person or owner of the opportunity.

To cater this I created a custom entity with a look up to Opportunity. There is a sub-grid that shows the associated view on the Opportunity form. There are 3 parts to it. For now I can do things with business rules and workflow:

  1. When a new Opportunity is created a new record is created in Split Percentage entity with the owner's name assigned 100 percent split and value of estimated revenue from an opportunity.
  2. If anyone wants to add a new sales person to this opportunity, they add it through the grid in Opportunity form. You add percentage of split this new sales person should have e.g. 10% and their estimated revenue will be calculated e.g. 10% of $1000 is $100 which is the value assigned to that record.

Now the third part is where I am stuck at, deducting the value assigned to the new sales person from the total revenue of the owner. In the example above the value of owner should change from $1000 to $900.

I am not sure how to update the Estimated Revenue of the owner every time a new sales person is added to the Opportunity.

1

1 Answers

2
votes

You can achieve this in post-create & post-update plugin on split percentage entity.

Whenever a new record is created in split percentage entity, plugin will trigger & update the owner’s split percentage record value based on the opportunity owner attribute. You have to retrieve the related child entity by proper filtering using fetchxml or QueryExpression and update back using service.Update

You have to recalculate in post update as well, if there is any change in % for non-owner records. Again you have to retrieve the related child entity by proper filtering using fetchxml or QueryExpression and update back using service.Update