Custom plug-in handling by using a shared variable
Issue
- Create and update operations on Opportunity, Quote, Order, and Invoice entities are triggering updates on their parent entities.
- Retrieving details about Opportunity, Quote, Order, and Invoice entities internally trigger the Price Calculation service, which subsequently triggers custom plug-ins created by customers.
Resolution
Custom plug-ins execute create, update, and save operations on Opportunity, Quote, Order, and Invoice entities. Create and update operations on these entities internally trigger the Price Calculation service, which then updates associated price-related fields or attributes of their parent entities.
You can identify or differentiate any updates in Opportunity, Quote, Order, or Invoice entities or parent Opportunity, Quote, Order, or Invoice entities by using the internal Price Calculation service or by using your own custom plug-in. The Boolean shared variable InternalSystemPriceCalculationEvent, which is accessible through IPluginExecutionContext, is available within the plug-in code. Any create or update event processed by using the Price Calculation service will set the value of the variable InternalSystemPriceCalculationEvent to true. The default value of InternalSystemPriceCalculationEvent is false. You can access this variable from your custom plug-in code to control the flow of your existing business logic.
Note
To perform custom plug-in operations by using a shared variable, make sure that the out-of-the-box Price Calculation service is disabled.
Sample code
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the tracing service
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext executionContext = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext))
bool isInternalSystemPriceCalculationEvent = false;
//Check existence of shared variable and fetch the value from executionContext
if (executionContext.ParentContext != null && executionContext.ParentContext.SharedVariables.ContainsKey("InternalSystemPriceCalculationEvent"))
{
isInternalSystemPriceCalculationEvent = (bool)executionContext.ParentContext.SharedVariables["InternalSystemPriceCalculationEvent"];
}
if (isInternalSystemPriceCalculationEvent)
{
//TO DO - Add or skip custom business logic
}
}
See also
Developer guide for Dynamics 365 Sales overview
Organization entity reference
System user entity reference
Quote, order, and invoice entities
Feedback
Trimiteți și vizualizați feedback pentru