I wrote two plugins for CRM Dynamics 2011. One is configured to be triggered during the creation of an Opportunity Product (Step added with Message set to "Create"). The other is configured to be triggered during the update of an Opportunity Product (Step added with Message set to "Update"). Both plugins write CRM data to an external SQL database (insert in one case, update in the other).
The first plugin alone works great (Pre operation). It's only called during opportunity product creation and the data is successfully written to my external database.
Once I activate the second plugin (Post operation + pre image), if I edit an opportunity product, it works great too. However, the plugins is also called when I create a new one... I really don't understand where this is coming from as I made sure of the following: - The two plugins are completely separated. I have two different assembly with a single step in each. - In each plugin, I have a condition checking the context.MessageName value (Create or Update) before the code is ran.
Do you guys have an idea where this is coming from ?
EDIT 1 (18/12/2013): I believe the Update plugin is called upon creation because of a "On Save" workflow that actually update some fields in the opportunity product. I am aiming toward using SharedVariables to prevent the execution of the Update plugin if the Create plugin is ran first. Here is the code used for sharing a variable between the two plugins. The SharedVariables.Contains check in the Update plugin is always false. To test this I create a brand new Opportunity Product while debugging the Update plugin.
Create Plugin
Dim setFlag As Boolean = True
context.SharedVariables.Add("NewSFR", setFlag)
Update Plugin
If context.SharedVariables.Contains("NewSFR") Then
Dim receivedFlag As Boolean = context.SharedVariables("NewSFR")
If receivedFlag Then
Return
End If
End If