Plugins Development in Dynamics 365 CRM | Part 3 – Adding Logic

Given that you are coming here from the Part 2: Plugins Development in Dynamics 365 CRM | Part 2 – Registering your plugin

Let’s add logic to catch the Group Code field value and retrieve all the Contacts under the Account to update their Group Code fields!

Context of the Plugin

Since this plugin is registered on one of the common messages like Update, let’s capture the context of the Update record we are working on –

  1. I’ll write a new method to just capture the context. If you are an expert in C#, you could smartly implement this than I have done. 😊
    Here, once the service, context and trace are set, you can have a new method to capture the context.
    In GetRecordContext() method, context.InputParameters[“Target”] will give you what is captured in the current Update context of the specific record you are running this plugin on.
    Typecase it into Entity so that you can retrieve required values from Entity currentEntity .

    Here, I’ve null-checked if the value is a part of the context update (in case the plugin unknowingly set to run on update of all fields), then I’m capturing the field value in a String variable to pass further.
    Once I capture the field value, I’ll pass it to GetAllChilRecords() method
  2. Next, in GetAllChildRecords(groupCode) method, I’m passing the updated string value further so that it can be updated to all retrieved child records.
    Here, I’m using FetchXML query to retrieve the Contacts which have the Company Name field i.e. the Account lookup set to the current record (current Account record on which we are updating the Group Code field)
    Quick Post on FetchXML attributes: Get all attributes in FetchXML in Plugins | Dynamics 365 CRM [Quick Tip]

    Now, there’s a purposeful mistake in the commented code above which we’ll see in the Debugging plugin part of this blog series.

  3. Finally, I’ll Rebuild this code, Update and run the plugin.

Updating the Plugin

Now, let’s say you have updated the code and now you want to re-deploy the plugin code.

  1. Once you have Rebuild. I use Ctrl + Shift + B.

  2. Next, you need to go to the Plugin Registration Tool, select the Plugin Assembly itself and click on Update.

  3. On this screen, even though you see your plugin already selected, click on the three dots to reselect the Assembly and select the .dll file as you originally did while registering it the first time.

  4. And then reselect the assembly and the plugin both and then click on Update Selected Plugins.


  5. Upon correctly updating, the below message is seen and you are done.

  6. Now, let’s run the code and see the “expected” Exception it will throw since we had commented a line on purpose in step #2 in Context of the Plugin section above. 😊

Exceptions

Now, when there are exceptions, you’ll typically see a error pop-up in Dynamics 365 as shown below

And since we can’t tell what it means, we’ll need to debug the plugin to find out the issue.

Let’s move to our Part 4 of the series to see how we can Debug a Plugin: Plugins Development in Dynamics 365 CRM | Part 4 – Debugging the plugin

Hope this was helpful! Here are some more Dynamics 365 posts which you might be interested in –

  1. Dynamics 365 Storage Utilization | Dataverse Storage | Power Platform Admin Center
  2. Use Hierarchy in Roll Up Fields in Dynamics 365 CRM
  3. Filter records in a View owned by a Team you are a member of | Dynamics 365 CRM
  4. Get GUID of the current View in Dynamics 365 CRM JS from ribbon button | Ribbon Workbench
  5. Dynamics 365 App For Outlook missing on SiteMap in CRM? Use shortcut link [Quick Tip]
  6. Import lookup referencing records together in Dynamics 365 CRM | [Linking related entity data during Excel Import]
  7. Mailbox Alerts Hide/Show behavior in Dynamics 365 CRM
  8. Excel Importing Notes (Annotation) entity in Dynamics 365 CRM
  9. Enable/Disable the need to Approve Email for Mailboxes in Dynamics 365 CRM CE
  10. Call Azure Function from Dynamics 365 CRM using Webhooks
  11. Show Ribbon button only on record selection in Dynamics CRM
  12. Accessing multiple occurrences of a field in Business Process Flow using JS in D365 CRM

Thank you!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.