简体   繁体   English

获取导致检索多个请求的查找-Dynamics 365插件

[英]Get lookup which causes retrieve multiple request - dynamics 365 plugin

I am using a pre-operation retrieve multiple plugin to add a condition to account subgrid lookups. 我正在使用术前检索多个插件为帐户子网格查找添加条件。 This works fine, however it applies to all queries on account entities. 这可以正常工作,但是它适用于对帐户实体的所有查询。 I want it to only apply when the user accesses the lookup within one subgrid on one form. 我希望它仅在用户访问一种形式的一个子网格内的查找时才适用。 Is there any way to retrieve the lookup which fires the query? 有什么方法可以检索触发查询的查询? Alternatively is the any way to achieve what I want to do by other means? 或者,是否可以通过其他方式实现我想做的任何事情? The purpose of this is to filter the accounts which can be added to the subgrid. 这样做的目的是过滤可以添加到子网格中的帐户。

Here is my code: 这是我的代码:

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;
                }
            }

        }
    }

On the criteria for the lookup view, add something like “Name” equals “FilterMe”. 在查找视图的条件上,添加“ Name”等于“ FilterMe”之类的内容。

Now in your plugin, inspect the incoming fetchxml query. 现在在您的插件中,检查传入的fetchxml查询。 If it contains your special criteria, you know to apply your special filtering. 如果它包含您的特殊条件,则您知道要应用特殊过滤。 Don't forget to remove the special criteria from the query in your code. 不要忘记从代码中的查询中删除特殊条件。

Now all other queries should not trigger your special filter. 现在,所有其他查询都不应触发您的特殊过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM