缺少 FetchXML 属性

FetchXML attribute missing

尝试使用 FetchXMLDynamics CRM 检索实体时,其中一个属性似乎丢失了。

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="sb_eventbooking">
    <attribute name="sb_name" />
    <attribute name="sb_bookeridname" />    < problem here
    <attribute name="createdon" />
    <atrribute ........

FetchXML 文件中有 18 个属性,但是 运行 应用程序只有 17 个可用:

并且缺少 sb_bookeridname。如果我进入 FetchXML 文件并输入一个我知道不存在的属性,那么我会得到一个错误:

'sb_eventbooking' entity doesn't contain attribute with Name = 'fakeattribute'.

所以应用程序接受 一个名为 'sb_bookeridname' 的属性,但我无法从中获取值。我知道具有 null 值的列可能存在问题,但其他属性似乎没有此问题。我确实对所有属性使用此检查并获取所有其他属性的值:

if (entity.Attributes.Contains("sb_bookeridname") && entity.GetAttributeValue<String>("sb_bookeridname") != null)
{
     booking.bookeridname = entity.GetAttributeValue<String>("sb_bookeridname");
}

编辑 1:

我相信您有一个具有架构名称的查找字段:sb_bookerid。当我们创建查找字段时,CRM会自动在table中创建一列来存储查找对应的文本值。因此,当我们创建查找字段 sb_bookerid 时,CRM 会自动在 sb_eventbooking 实体中创建一个列姓名 sb_bookerid姓名

这就是您在执行 FetchXML 查询时没有收到错误的原因,因为具有名称的列存在,但 CRM 限制显示其值。因此,如果您想检索 sb_bookerid 字段中的值,请使用以下 -

if(entity.Contains("sb_bookerid"))
{
bookeridname=((EntityReference)entity.Attributes["sb_bookerid"]).Name
}

希望对您有所帮助。

这是更简洁的方法:

bookeridname = entity.GetAttributeValue<EntityReference>("sb_bookerid")?.Name;