Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

plugin per entity vs plugin on multiple entities?

Posted on by Microsoft Employee

witch one is better having a plugin per entity with an SDK for common functions or creating specific plugins and generic plugins with multiple steps for multiple entities just to avoid redundancy ?

*This post is locked for comments

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: plugin per entity vs plugin on multiple entities?

    You need to design the plugin considering the existing functionality. For example if you have a workflow (Async) which updates the status to say In Progress. Then if you wrtite a plugin (sync) to change the status to Draft then it won't work as when the workflow runs it will change the status back to In Progress.

    So before implementing any custom logic (be it plugin, workflow etc), you need to review the current implementation and design based on that.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: plugin per entity vs plugin on multiple entities?

    @Ravi Kashyap then how do you manage that confilct? , or a plug per entity would be recomanded in this case

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: plugin per entity vs plugin on multiple entities?

    Hi,

    "doesn’t that mean that we could have some plugin interfering with the work of others? " - Yes and this happens lot of the time not only with custom plugin but with OOB plugins as well. I have seen spo may cases now where we have custom plugin on quote/quote details for the tax calculate which are interfering with Dynamics.Sales.Plugin OOB plugins.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: plugin per entity vs plugin on multiple entities?

    @Mohamed HAJJI: No switch statements. While they are, like any other control structure, useful in certain scenarios more often than not, they are abused. The Case Management plugin is specifically for any actions on the Case entity.

    So, I wouldn't have any switch statements (I wouldn't write code with any switch statements if I can help it) on entity. I am assuming that you meant switch based on attributes? If so, no...that is an almost bad idea unless the change of two different attributes triggers the exact same business logic.

    In my example, I have OnCaseTypeUpdate.cs - this is a plugin class which will be triggered only when the case type field is updated. If I wanted functionality on update of classification field of the Case entity, I would rather have a plugin class called OnCaseClassificationUpdate unless you want the exact same logic to be executed on update of either field (but then again, if you wanted some additional custom logic, you run into the same problem of creating plugin class for update / create mentioned above).

    - Sara

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: plugin per entity vs plugin on multiple entities?

    Sara W Ellis, sorry i didn't specify , i was talking about entity dependent actions (like update a specific field when this happened ...) , i'm  assuming that for the Case Management Plugin you have a switch base on entity sometimes?

    if yes my second question would be why separate by action and not by entity for example?

    Ravi Kashyap if we sort plugins by  common Requirement, doesn’t that mean that we could have some plugin interfering with the work of others?

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: plugin per entity vs plugin on multiple entities?

    Hi,

    As you have mentioned Common Requirement, it is better to go for the single plugin. However, If you have some common requirement which you think can be reused across multiple entity then you can go for Custom Workflow Activity. This is one of the criteria I revisit to decide between Plugin & Custom Workflow. The advantage of CWA is that you could have input / output parameters and non technical users can also use it without having to connect to PLT and registering new steps. More control with respect to maintenance.

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: plugin per entity vs plugin on multiple entities?

    This is a largely subjective question and I do not think there is any one correct answer. 

    Here is a scenario. 

    Requirement #1: Document Management System

    1. When a case gets created, I want some custom functionality happening in a (assume non-SharePoint or requires custom development) Document Management System (DMS)
    2. When a case type is updated, I want custom functionality in DMS. 
    3. When a case is closed, I want custom functionality in DMS. 
    4. When a case is re-activated, I want custom functionality in DMS. 
    5. When I share a record, I want custom functionality in DMS. 
      1. Each Sharing Access Right, invokes a different functionality...i.e., when Read permissions is given I want a functionality and when Write permissions is given, I want another functionality. 
    6. When I assign a record, I want custom functionality in DMS. 

    Requirement #2: Case Management

    1. On create - custom logic
    2. On update of type - custom logic
    3. On change of status - custom logic
    4. ...
    5. ...

    You can design them as two different plugin assemblies, one for Document Management System and other for Case Management. The Document Management System assembly, will contain a plugin for each of the requirements. Similarly, the Case Management will contain a different plugin assembly with a plugin for each of the requirements. 

    I would generally have one plugin assembly but separate plugin for Create / specific Updates / status change (split them into - one for close and one for reactivated?...or is that taking it too far? :-) ). My plugin folder will look something like this

    -Plugins

    |--Case Management Plugin

    |    |--OnCaseCreate.cs

    |    |--OnCaseTypeUpdate.cs

    |    |--OnCaseClose.cs

    |    |--OnCaseReactivated.cs

    |    |--OnCaseAssigned.cs

    |--Document Management Plugin

    |    |--OnCaseCreateRefreshDMS.cs

    |    |--OnCaseTypeUpdateRefreshDMS.cs

    |    |--OnCaseCloseRefreshDMS.cs

    |    |--OnCaseReactivatedRefreshDMS.cs

    |    |--OnCaseAssignedRefreshDMS.cs

    I haven't listed the other folders (CrmPackage) / and files Entities.cs, but you get the idea. 

     


    The general thumb rule (in my opinion, based on how CRM is organized - i.e., within Sales you have Opportunity, Quotes, Orders, Invoices etc., and within Service you have Case, Entitlements etc., ) is to segregate by entity and then by functionality to identify how many plugin assemblies you require. Within the plugin assemblies, I would keep the triggers as isolated as possible. There is little point in combining a Create and Update (yes, there are scenarios when a lot of is just common code) in the same plugin class, only to realize a month later that you need to start writing statements such as 

    if (localcontext.PluginExecutionContext.MessageName.ToLower() == "create")
    
    {
    
    //Do specific functionality for create
    
    }
    
    else
    
    {
    
    //Do functionality for update
    
    }
    
    //Continue with common functionality. 


    Instead, just put the common functionality in a Shared Library and call them from within the two plugin (classes). 

    However, there is always generic functionality, but that should be ideally entity agnostic.

    For instance, if you have a requirement to send emails (use workflows!) for when one of these entities is created and set the regarding to that particular record, then create

    1. one plugin assembly called Common Email Management;
    2. have one plugin within the assembly called GenericEnitityOnCreateSendEmail.
    3. Register multiple steps in the same plugin for each of the entity. 

    Hope that helps. 

    -Sara

  • gdas Profile Picture
    gdas 50,085 on at
    RE: plugin per entity vs plugin on multiple entities?

    Hello ,

    If you need to execute same logic and the plugins does not depends on entity  attributes then you should reuse the plugin instead of create different plugin class for each entity.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans