0
votes

In our Dynamics 365 instance, we've got a custom entity called Activity entry which is associated with out of box Project entity. These 2 entities are associated with a N:N relationship.

Hence, each project can have multiple entities associated with it.

Problem:

Get a total count of Activity entry entities when they're associated to the Project entity such that when

  • an Activity entry is associated with a Project entity, increment the activities count
  • an Activity entry is disassociated with a Project entity, decrement the activities count

What we've tried so far?

We've tried to implement a workflow process to get this thing, but couldn't understand this association/dis-association aspect

1

1 Answers

1
votes

I know you asked about a workflow process but you can also create a plug-in for the Associate message to accomplish your requirement.

An Associate message plug-in is a bit different from plug-ins for other messages: You register it without specifying a primary or secondary entity. It therefore runs for every association made in your system.

Your code needs to check the execution context and see which two entities are involved. In your case, if the entities are Activity and Project, you can increment your counters.

Note that if you have two N:N relationships between these two entities, you will also need to check that you are responding to the correct relationship.