/// <summary>
/// In v9.0, on preoperation of Create SDK of QOIS entity (Quote, Opportunity, Invoice, SalesOrder) and
/// post operation of Update, Retrieve SDK of QOIS entity, the CalculatePricePlugin is explictly called.
/// If CalculatePricePlugin internally calls CRU Actions on QOIS entity, then we have infinite loop.
/// </summary>
/// <param name="context"></param>
/// <param name="traceService"></param>
/// <returns>Returns true, if the current PluginStep is called due to Pre Or Post Operation of CRUActions on QOIS entity</returns>
private bool IsThisPluginStepCalledByPreOrPostOperationofCRUSDKOnQOISEntity(IPluginExecutionContext context, ITracingService traceService)
{
traceService.Trace("Parent: Primary Entity Name {0} and SDK Message Name {1}",
context.ParentContext.PrimaryEntityName,
context.ParentContext.MessageName);
List<String> updatedentities = new List<string>(new string[] { "quote", "salesorder", "invoice", "opportunity" });
List<String> updatedSDKMessage = new List<string>(new string[] { "Create", "Retrieve", "Update" });
if (context.ParentContext != null)
{
var parentEntityName = context.ParentContext.PrimaryEntityName;
if (updatedentities.Contains(parentEntityName))
{
var ParentSDKMessageName = context.ParentContext.MessageName;
if (updatedSDKMessage.Contains(ParentSDKMessageName))
return true;
}
}
return false;
}
You can use above function in your execute function of plugin step. if the below function returns true, do not execute the plugin. For e.g.
public void Execute(IServiceProvider serviceProvider)
{
if (IsThisPluginStepCalledByPreOrPostOperationofCRUSDKOnQOISEntity(context, traceService))
return;
// your code
}