如何使用“ QueryExpression”对象从CRM获取所有填充的列? [英] How to get all populated columns from CRM using `QueryExpression` object?

查看:134
本文介绍了如何使用“ QueryExpression”对象从CRM获取所有填充的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里,答案解决了我的问题。但是,现在我遇到了与以前相同的问题,但由于条件的变化,答案不再起作用。

I've asked a similar question before here and the answer solved my problem. However, now I'm getting the same problem as before but the answer doesn't work anymore due to change in conditions.

这里是查询我正在运行。我检查了 someField 是否设置为某种值(这是一个由GUID引用其他实体的查找字段)。在结果中没有任何条目(除非我将条件切换为不相等)。

Here's the query I'm running. I've checked that someField is set to something (it's a look-up field referring to an other entity by a guid). I get no entries in result (unless I switch the condition to "not equal"). That's probably due to the fact that the field isn't brought in.

当我断点执行并检查属性,我总共看到了30个字段中的21个(当然,其中某些字段可能为空,但是这个一个字段,即 someField 不是),但是我感兴趣的那个不在!

When i breakpoint the execution and check Attributes, I see 21 fields out of a total of 30 (some of them might be empty, sure, but this one, i.e. someField, is not) but the one I'm interested in, isn't there!

QueryExpression query = new QueryExpression
{
  EntityName = "entity",
  ColumnSet = new ColumnSet{ AllColumns = true },
  // Here I tried the code addition #1 below
  Criteria =
  {
    Filters =
    {
      new FilterExpression
      {
        Conditions =
        {
          new ConditionExpression("someField", ConditionOperator.Equal, guid)
        }
      }
    }
  }
};
// Here I tried the code addition #2 below
EntityCollection result = Service.RetrieveMultiple(query);

我想念什么,如何解决?

What do I miss and how can I resolve it?

我曾尝试使用LinkEntities 与associatedeassociate-plugin一起工作 / rel = nofollow noreferrer>此博客,但实际上并没有解决。我什至不确定这是否有意义。看起来如下。

I tried using LinkEntities as discussed in this blog but it didn't really work out. I'm not even sure if it was a meaningful approach. It looked as follows.

  LinkEntities =
  {
    new LinkEntity
    {
      Columns = new ColumnSet { AllColumns = true },
      LinkFromEntityName = "entity",
      LinkFromAttributeName = "otherEntityId",
      LinkToEntityName = "entity2",
      LinkToAttributeName = "entity2Id"
    }
  },

我也尝试使用解决方案。相同的结果。

I also tried to employ the solution suggested on MSDN. The same result.

request.LinkEntities.Add(
  new LinkEntity(
    "entity", "entity2", "otherEntityId", "entity2Id", JoinOperator.Inner));
request.LinkEntities[0].Columns.AddColumns("entity2Id");
request.LinkEntities[0].EntityAlias = "blobb";

再一次-@JamesWood提供的解决方案不再起作用,因为我已获得管理员访问权限,并且字段不是空的。

Once again - the solution provided by @JamesWood isn't working anymore, since I've got the administrator access and the regarded field is not empty.

推荐答案

I相信这里的问题在于您的 FilterExpression 和/或实际数据本身。

I believe the issue here is in your FilterExpression and/or the actual data itself.

根据您在此处的所说:


结果中没有任何条目(除非我将条件切换为 not
equal)

I get no entries in result (unless I switch the condition to "not equal")

将过滤器设置为等于时,没有任何东西等于该Guid,因此您不会得到结果。

When you set the filter to "equal", nothing is equal to that Guid so you get no results.

将过滤器设置为不等于时,所有条件都不等于该条件,因此您开始获得一些结果。当您获得结果时,将不包含查找,因为该记录为空(以及为什么相等过滤器不起作用)。

When you set the filter to "not equal", everything is not equal to that condition so you start getting some results. When you do get results the lookup is not included because it is null the record (and hence why the "equal" filter doesn't work).

对于确切的问题尚不确定,我建议您采取以下步骤:

As I'm not certain about the exact issue I suggest taking these steps:


  1. 对于该记录类型,删除所有记录。

  2. 创建一条新记录,填充查找字段。

  3. 编写查询以返回该实体的所有字段(例如 AllColumns = true 指定 FilterExpression

  4. 此查询应为您提供一个结果,请检查属性集合以确保填充了查询(检查所有属性以确保您输入的名称不正确)。

  5. 然后将查询扩展为具有 FilterExpression

  1. For that record type, delete all the records.
  2. Make one new record, populate the lookup field.
  3. Write a query that returns all fields from that entity (e.g. AllColumns = true) without specifying a FilterExpression.
  4. This query should give you one result, inspect the attributes collection to make sure the lookup is populated (check all the attributes to make sure you haven't just got the wrong name).
  5. Then extend the query to have a FilterExpression.

有一个使用查找过滤的示例此处

There is an example of filtering with a lookup here.

与ide note;您实际上不必在要用于过滤的 ColumnSet 列中进行指定。

As a side note; you don't actually have to specify in the ColumnSet columns you are going to use for filtering.

例如在SQL中,您可以执行以下操作:

E.g. in SQL you could do:

SELECT firstname FROM contact WHERE lastname = 'wood'

这篇关于如何使用“ QueryExpression”对象从CRM获取所有填充的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆