1

当输入参数查询的类型为 Fetch Expression 时,请建议如何使用 RetrieveMultiple 插件中的以下相同查询表达式过滤 CRM/模型驱动应用程序统一客户端界面视图:

FilterExpression filter = new FilterExpression(LogicalOperator.Or);

string[] sourceChannel = new string[] { "Central Bank", "AECB" };

FilterExpression filter1 = new FilterExpression(LogicalOperator.And);
filter1.Conditions.Add(new ConditionExpression("sourcechannelidname", ConditionOperator.NotIn, sourceChannel));
filter1.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

FilterExpression filter2 = new FilterExpression(LogicalOperator.And);
filter2.Conditions.Add(new ConditionExpression("sourcechannelidname", ConditionOperator.In, sourceChannel));
filter2.Conditions.Add(new ConditionExpression("valid", ConditionOperator.Equal, 1));
filter2.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

FilterExpression filter3 = new FilterExpression(LogicalOperator.And);
filter3.Conditions.Add(new ConditionExpression("sourcechannelidname", ConditionOperator.In, sourceChannel));
filter3.Conditions.Add(new ConditionExpression("valid", ConditionOperator.Equal, 2));
filter3.Conditions.Add(new ConditionExpression("reopeningcount", ConditionOperator.GreaterThan, 0));
filter3.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

FilterExpression filter4 = new FilterExpression(LogicalOperator.And);
filter4.Conditions.Add(new ConditionExpression("sourcechannelidname", ConditionOperator.In, sourceChannel));
filter4.Conditions.Add(new ConditionExpression("valid", ConditionOperator.Equal, 2));
filter4.Conditions.Add(new ConditionExpression("statecode", ConditionOperator.NotEqual, 0));
filter4.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

filter.AddFilter(filter1);
filter.AddFilter(filter2);
filter.AddFilter(filter3);
filter.AddFilter(filter4);

qe.Criteria.AddFilter(filter);

我在下面尝试了从 Microsoft 文档中获取帮助,如下所述:

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/org-service/samples/modify-query-preoperation-stage

但我不知道如何将 And 和 OR 过滤器类型放在 XML 文档下面。

任何帮助或指导将不胜感激。

entityElement.Add(
  new XElement("filter",
    new XElement("condition",
      new XAttribute("attribute", "sourcechannelidname"),
      new XAttribute("operator", "not-in"), //not equal
      new XElement("value", new XText("Central Bank")),
      new XElement("value", new XText("AECB"))
    ),
    new XElement("condition",
      new XAttribute("attribute", "casetypecode"),
      new XAttribute("operator", "eq"), //equal
      new XAttribute("value", "1"), //Complaints
    )
  )
);
4

2 回答 2

1

在 FetchXml 中,您尝试编写的表达式是(参见type='and'):

<filter type='and' >
  <condition attribute='sourcechannelidname' operator='not-in' >
    <value>Central Bank</value>
    <value>AECB</value>
  </condition>
  <condition attribute='casetypecode' operator='eq' value='1' >
</filter>

所以我认为你只需要XAttribute在“过滤器”上指定一个XElement

entityElement.Add(
  new XElement("filter",
    new XAttribute("type", "and"),
    new XElement("condition",
      new XAttribute("attribute", "sourcechannelidname"),
      new XAttribute("operator", "not-in"), //not equal
      new XElement("value", new XText("Central Bank")),
      new XElement("value", new XText("AECB"))
    ),
    new XElement("condition",
      new XAttribute("attribute", "casetypecode"),
      new XAttribute("operator", "eq"), //equal
      new XAttribute("value", "1"), //Complaints
    )
  )
);
于 2021-07-29T05:04:54.550 回答
0

XrmToolbox 现在可以将 C# 解析为 fetch 表达式。只需使用“查看”菜单并选择“QueryExpression”来打开窗口,然后在其中输入(或粘贴)您的有效代码并单击“解析”,它将为您将其转换为 FetchXml。您没有包含完整的 fetchXml 查询,并且我不认识字段名称,但我将其复制到 OOTB 事件查询(因为我知道它有一个 casetypecode 字段)并将字段名称替换为相同的类型。我为它们设置了参数,因此您可以轻松地将它们替换为您自己的参数。这是我使用的代码:

// Instantiate QueryExpression query
var query = new QueryExpression("incident");
query.TopCount = 50;

// Add all columns to query.ColumnSet
query.ColumnSet.AllColumns = true;

FilterExpression filter = new FilterExpression(LogicalOperator.Or);

string[] sourceChannel = new string[] { "Central Bank", "AECB" };
var stringColName = "ticketnumber";
var intColName = "timezoneruleversionnumber";
var pickColName = "servicestage";

FilterExpression filter1 = new FilterExpression(LogicalOperator.And);
filter1.Conditions.Add(new ConditionExpression(stringColName, ConditionOperator.NotIn, sourceChannel));
filter1.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

FilterExpression filter2 = new FilterExpression(LogicalOperator.And);
filter2.Conditions.Add(new ConditionExpression(stringColName, ConditionOperator.In, sourceChannel));
filter2.Conditions.Add(new ConditionExpression(pickColName , ConditionOperator.Equal, 1));
filter2.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

FilterExpression filter3 = new FilterExpression(LogicalOperator.And);
filter3.Conditions.Add(new ConditionExpression(stringColName, ConditionOperator.In, sourceChannel));
filter3.Conditions.Add(new ConditionExpression(pickColName , ConditionOperator.Equal, 2));
filter3.Conditions.Add(new ConditionExpression(intColName, ConditionOperator.GreaterThan, 0));
filter3.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

FilterExpression filter4 = new FilterExpression(LogicalOperator.And);
filter4.Conditions.Add(new ConditionExpression(stringColName, ConditionOperator.In, sourceChannel));
filter4.Conditions.Add(new ConditionExpression(pickColName , ConditionOperator.Equal, 2));
filter4.Conditions.Add(new ConditionExpression("statecode", ConditionOperator.NotEqual, 0));
filter4.Conditions.Add(new ConditionExpression("casetypecode", ConditionOperator.Equal, 1));

filter.AddFilter(filter1);
filter.AddFilter(filter2);
filter.AddFilter(filter3);
filter.AddFilter(filter4);

query.Criteria.AddFilter(filter); 

这是它创建的过滤器:

<filter type="and" >
  <filter type="or" >
    <filter type="and" >
      <condition attribute="ticketnumber" operator="not-in" >
        <value>Central Bank</value>
        <value>AECB</value>
      </condition>
      <condition attribute="casetypecode" operator="eq" value="1" />
    </filter>
    <filter type="and" >
      <condition attribute="ticketnumber" operator="in" >
        <value>Central Bank</value>
        <value>AECB</value>
      </condition>
      <condition attribute="servicestage" operator="eq" value="1" />
      <condition attribute="casetypecode" operator="eq" value="1" />
    </filter>
    <filter type="and" >
      <condition attribute="ticketnumber" operator="in" >
        <value>Central Bank</value>
        <value>AECB</value>
      </condition>
      <condition attribute="servicestage" operator="eq" value="2" />
      <condition attribute="timezoneruleversionnumber" operator="gt" value="0" />
      <condition attribute="casetypecode" operator="eq" value="1" />
    </filter>
    <filter type="and" >
      <condition attribute="ticketnumber" operator="in" >
        <value>Central Bank</value>
        <value>AECB</value>
      </condition>
      <condition attribute="servicestage" operator="eq" value="2" />
      <condition attribute="statecode" operator="ne" value="0" />
      <condition attribute="casetypecode" operator="eq" value="1" />
    </filter>
  </filter>
</filter>
于 2021-08-02T21:47:09.993 回答