2
votes

I wrote a plug-in for Dynamics CRM 2015 and I want to trigger it every time the user clicks on an account. When I register it with "Update" message, it's fired once. However, when I register with "Retrieve" message, it's fired multiple times. I tried this code below but it didn't work:

if (context.Depth > 1)
{
      tracingService.Trace("Depth > 1");
      return;
}

I checked the Trace Logs and saw that the plug-in was fired three times in a row (with the same depth = 1). If I set the Excution Mode from Sync to Async, the plug-in will be fired 6 times.

Any advice, please?

Edit: This is my plug-in registration

enter image description here

This is the plug-in was fired three times in Trace Log

enter image description here

1
What is your goal? what do you want to achieve?Yaqub Ahmad
I want to write a plug-in such that whenever the user clicks on an account (to see its details), this plug-in will be triggered to run to insert some kinds of data to the database. So I register this plug-in with Retrieve message. However, when the user clicks on an account, this plug-in is fired three times (hence it inserts the same data three times). I only want this plug-in to run ONCE.user3305040
Can you post an image of the plugin registration?budahead
Please check the updated post. Thanks!user3305040
is there perhaps code in your plugin that initiates another retrieve for information on that record? Can you post your whole plugin to confirm that? or else there could be javascript that runs when the page loads that does a SOAP/OData retrieve on this record.Joseph Duty

1 Answers

1
votes

If your intention is to do some sort of logging when a user tries to view any of the account details: you should write your custom logic in the Form load of the main entity form (or any of the desired forms) of Account.

Internally Retrieve could be used to display many information or to perform different business logic. So triggering your plugin on Retrieve can bring duplicate entries for the same record. Hope this helps.