gpt4 book ai didi

c# - 抓取用户列表存在于 dynamics crm 中的关系中

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:55 25 4
gpt4 key购买 nike

我在 dynamics crm 表单订单到系统用户中有多对多关系,从下面的代码片段我试图获取退出这种关系的用户列表。但这会引发异常,即 Additional information: 'SystemUser' entity doesn't contain attribute with Name = 'salesorderid'.

知道吗,我缺少什么?

private void grabRelatedUsers(IOrganizationService service){
QueryExpression sysUsersQuery = new QueryExpression()
{
EntityName = "systemuser",
ColumnSet = new ColumnSet("systemuserid"),
LinkEntities = {
new LinkEntity() {
LinkFromEntityName = "systemuser",
LinkToEntityName = "new_salesorder_systemuser",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
JoinOperator = JoinOperator.Inner
},
new LinkEntity() {
LinkFromEntityName = "new_salesorder_systemuser",
LinkToEntityName = "salesorder",
LinkFromAttributeName = "salesorderid",
LinkToAttributeName = "salesorderid",
JoinOperator = JoinOperator.Inner,
LinkCriteria = new FilterExpression() {
Conditions = {
new ConditionExpression("salesorderid",ConditionOperator.Equal,orderId)
}
}
},
new LinkEntity().AddLink("systemuser","systemuserid","systemuserid")
},

};

EntityCollection subGridUsers = service.RetrieveMultiple(sysUsersQuery);
}

最佳答案

您没有正确嵌套链接实体。查看为您的场景生成的 fetchXML:

<fetch version="1.0" output-format="xml-platform" mapping="logical">
<entity name="systemuser">
<attribute name="systemuserid" />
<link-entity name="new_salesorder_systemuser" from="systemuserid" to="systemuserid" visible="false" intersect="true">
<link-entity name="salesorder" from="salesorderid" to="salesorderid" alias="ab">
<filter type="and">
<condition attribute="salesorderid" operator="eq" value="XXXXXXXXXXXXXXX" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>

如您所见,链接的实体必须是嵌套的,而且,由于开箱即用的 N:N 关系,您不能从 new_salesorder_systemuser 链接 salesorder,而是从 systemuser。所以 QueryExpression 应该是这样的:

QueryExpression sysUsersQuery = new QueryExpression()
{
EntityName = "systemuser",
ColumnSet = new ColumnSet("systemuserid"),
LinkEntities = {
new LinkEntity
{
LinkFromEntityName = "systemuser",
LinkToEntityName = "new_salesorder_systemuser",
LinkFromAttributeName = "systemuserid",
LinkToAttributeName = "systemuserid",
JoinOperator = JoinOperator.Inner,
LinkEntities =
{
new LinkEntity()
{
EntityAlias = "ab",
LinkFromEntityName = "systemuser",
LinkToEntityName = "salesorder",
LinkFromAttributeName = "salesorderid",
LinkToAttributeName = "salesorderid",
JoinOperator = JoinOperator.Inner,
LinkCriteria = new FilterExpression()
{
Conditions = {
new ConditionExpression("salesorderid",ConditionOperator.Equal, "sfsdf")
}
}
}
}
}
}
};

如果您在生成 QueryExpressions 时遇到问题,只需使用 Advanced Find 进行查询,下载 fetchXml 并使用 SDK FetchXmlToQueryExpressionRequest 消息将其转换为 QueryExpression。这里有一些样本: https://msdn.microsoft.com/en-us/library/hh547457.aspx

关于c# - 抓取用户列表存在于 dynamics crm 中的关系中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42836062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com