效果:
源码实现:
public class test_RetrieveMultiple_pre : IPlugin { public void Execute(IServiceProvider serviceProvider) { //上下文 IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); //服务工厂 IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); //组织服务 IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); //管理员组织服务 IOrganizationService serviceAdmin = serviceFactory.CreateOrganizationService(null); QueryExpression query = null; if (context.InputParameters.Contains("Query") && context.InputParameters["Query"] is QueryExpression) { query = (QueryExpression)context.InputParameters["Query"]; } else if (context.InputParameters.Contains("Query") && context.InputParameters["Query"] is FetchExpression) { FetchExpression fetch = (FetchExpression)context.InputParameters["Query"]; var conversionRequest = new FetchXmlToQueryExpressionRequest { FetchXml = fetch.Query }; var conversionResponse = (FetchXmlToQueryExpressionResponse)serviceAdmin.Execute(conversionRequest); query = conversionResponse.Query; } if (query == null) return; foreach (var item in query.Criteria.Conditions) { if (item.AttributeName.Contains("name")) { //判断原有条件的符号是否是等于 if (item.Operator != ConditionOperator.Equal) return; //拆分,根据空格拆分 string[] valueStr = item.Values.First().ToString().Split(' '); //组装新条件 query.Criteria.AddCondition(item.AttributeName, ConditionOperator.In, valueStr); //将原有条件移除 query.Criteria.Conditions.Remove(item); break; } } context.InputParameters["Query"] = query; } }
标签:复制到,InputParameters,视图,item,context,query,Query,Dynamics From: https://www.cnblogs.com/parkerchen/p/17075832.html