[英]CRM 4.0 - FetchXML to retrieve data from related entity
I'm trying to use FetchXML to pull in a list of courses with an 'entry year' related entity. 我正在尝试使用FetchXML来获取与“入学年”相关实体的课程列表。 What I would like to do is only return a single record for each course (could return multiple courses) with the latest year (eg I would want it to pick the last year out of 2012, 2013, 2014 - so in this case 2014). 我想做的是只返回每门课程的单条记录(可以返回多门课程)的最新年份(例如,我希望它选择2012、2013、2014年中的最后一年-在这种情况下为2014年) 。 So I currently have: 所以我目前有:
<fetch mapping="logical" distinct="true">
<entity name="course">
<all-attributes/>
<order attribute="name" />
<link-entity name="course_entryyear" from="courseid" to="courseid">
<link-entity name="entryyear" from="entryyearid" to="entryyearid">
<attribute name="year" />
</link-entity>
</link-entity>
</entity>
</fetch>
Is this possible to do within FetchXML and if so how can I amend the above? 在FetchXML中可以这样做吗?如果可以,我该如何修改上面的内容?
Cheers 干杯
What about adding count="1" and inner join to the linked entities along with some ordering: 如何将count =“ 1”和内部联接添加到链接的实体以及一些顺序:
So it would look like: 因此,它看起来像:
<fetch mapping="logical" distinct="true">
<entity name="course">
<all-attributes/>
<order attribute="name" />
<link-entity name="course_entryyear" from="courseid" to="courseid" link-type="inner">
<link-entity name="entryyear" from="entryyearid" to="entryyearid" link-type="inner" count="1">
<attribute name="year" />
<order attribute="year" descending="true"/>
</link-entity>
</link-entity>
</entity>
</fetch>
Depending on how you are displaying the course list you might want to change the link-type for the "course-entryyear" from inner to outer , so that all courses get displayed even if they haven't been served yet. 根据您是如何显示的课程列表,你可能要更改链接类型从内到外的“当然,entryyear”,让所有的课程得到,即使他们尚未投放尚未显示出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.