当试图使用Dynamics CRM从FetchXML检索实体时,似乎缺少其中一个属性。
<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:

发布于 2018-11-27 13:57:50
我相信您有一个模式名为sb_bookerid的查找字段。当我们创建一个查找字段时,CRM会自动在表中创建一个列来存储与查找相对应的文本值。因此,当我们创建一个查找字段sb_bookerid时,客户关系管理将自动以名称sb_bookeridname在sb_eventbooking实体中创建一个列。
这就是为什么在执行FetchXML查询时没有收到错误的原因,因为具有名称的列存在,但CRM限制显示其值。因此,如果要检索sb_bookerid字段中的值,请使用以下-
if(entity.Contains("sb_bookerid"))
{
bookeridname=((EntityReference)entity.Attributes["sb_bookerid"]).Name
}希望能帮上忙。
发布于 2018-11-27 16:21:15
这里有一个更干净的方法:
bookeridname = entity.GetAttributeValue<EntityReference>("sb_bookerid")?.Name;https://stackoverflow.com/questions/53497521
复制相似问题