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 –
- 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 - 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. - 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.
- Once you have Rebuild. I use Ctrl + Shift + B.
- Next, you need to go to the Plugin Registration Tool, select the Plugin Assembly itself and click on Update.
- 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.
- And then reselect the assembly and the plugin both and then click on Update Selected Plugins.
- Upon correctly updating, the below message is seen and you are done.
- 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 –
- Dynamics 365 Storage Utilization | Dataverse Storage | Power Platform Admin Center
- Use Hierarchy in Roll Up Fields in Dynamics 365 CRM
- Filter records in a View owned by a Team you are a member of | Dynamics 365 CRM
- Get GUID of the current View in Dynamics 365 CRM JS from ribbon button | Ribbon Workbench
- Dynamics 365 App For Outlook missing on SiteMap in CRM? Use shortcut link [Quick Tip]
- Import lookup referencing records together in Dynamics 365 CRM | [Linking related entity data during Excel Import]
- Mailbox Alerts Hide/Show behavior in Dynamics 365 CRM
- Excel Importing Notes (Annotation) entity in Dynamics 365 CRM
- Enable/Disable the need to Approve Email for Mailboxes in Dynamics 365 CRM CE
- Call Azure Function from Dynamics 365 CRM using Webhooks
- Show Ribbon button only on record selection in Dynamics CRM
- Accessing multiple occurrences of a field in Business Process Flow using JS in D365 CRM
Thank you!!