[英]Get lookup which causes retrieve multiple request - dynamics 365 plugin
我正在使用術前檢索多個插件為帳戶子網格查找添加條件。 這可以正常工作,但是它適用於對帳戶實體的所有查詢。 我希望它僅在用戶訪問一種形式的一個子網格內的查找時才適用。 有什么方法可以檢索觸發查詢的查詢? 或者,是否可以通過其他方式實現我想做的任何事情? 這樣做的目的是過濾可以添加到子網格中的帳戶。
這是我的代碼:
public class FilterAversedSuppliers : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Query") &&
context.InputParameters["Query"] is QueryExpression)
{
try
{
QueryExpression objQueryExpression = (QueryExpression)context.InputParameters["Query"];
ConditionExpression condition = new ConditionExpression()
{
AttributeName = "customertypecode",
Operator = ConditionOperator.Equal,
Values = { 4 }
};
objQueryExpression.Criteria.AddCondition(condition);
tracingService.Trace("Custom Filter Added");
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the FollowupPlugin plug-in.", ex);
}
catch (Exception ex)
{
tracingService.Trace("FollowupPlugin: {0}", ex.ToString());
throw;
}
}
}
}
在查找視圖的條件上,添加“ Name”等於“ FilterMe”之類的內容。
現在在您的插件中,檢查傳入的fetchxml查詢。 如果它包含您的特殊條件,則您知道要應用特殊過濾。 不要忘記從代碼中的查詢中刪除特殊條件。
現在,所有其他查詢都不應觸發您的特殊過濾器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.