获取XML查询问题
本文关键字:问题 查询 XML 获取 | 更新日期: 2023-09-27 18:17:31
在我工作的公司内,我在Microsoft Dynamics CRM 2013中创建了一个名为Issue的新实体,在实体Issue中有一个子网格,用户可以从实体Cost To Business添加记录。
目的是用户在需要时添加记录。我现在使用FetchXML查询c#插件,以便我可以检索与子网格中的每条记录相关的成本属性,以便我可以填充总成本字段。
到目前为止,我有以下查询Guid orderID = (Guid)((Entity)context.InputParameters["Target"]).Id;
string fetchxml =
@"<fetch distinct='true' mapping='logical' output-format='xml-platform' version='1.0'>
<entity name='new_issue'>
<attribute name='new_issueid'/>
<attribute name='new_name'/>
<attribute name='createdon'/>
<order descending='false' attribute='new_issueid'/>
<filter type='and'>
<condition attribute='new_issueid' operator='eq' value='" + orderID + @"'/>
</filter>
<link-entity name = 'new_costtype' alias='ac' to='new_issueid' from='new_costtypeissueid'>
<link-entity name='new_costtobusiness' alias='ad' to='new_costtobusinesscosttypeid' from='new_costtobusinessid'>
<attribute name='new_coststring'/>
</link-entity>
</link-entity>
</entity>
</fetch>";
然而,查询不能返回任何东西,因为下面的代码没有被执行。
EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchxml));
if (result != null && result.Entities.Count > 0)
{
List<int> _product = new List<int>();
foreach (Entity _entity in result.Entities)//loop through every record
{
costToBusiness = ((AliasedValue)_entity.Attributes["ad.new_coststring"]).Value.ToString();
total = (total) + Convert.ToInt32(costToBusiness);
}
if(entity.Attributes.Contains("new_businessstring"))
{
entity.Attributes["new_businessstring"] = currencyName + total.ToString();
costToBusiness = "";
total = 0;
currencyName = "";
}
else
{
entity.Attributes.Add("new_businessstring", currencyName + total.ToString());
costToBusiness = "";
total = 0;
currencyName = "";
}
}
有没有人有一个原因/建议,为什么会发生这种情况?提前感谢
详细信息从下载日志从throw new invalidpluginexecutionexception
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: <fetch distinct='true' mapping='logical' output-format='xml-platform' version='1.0'>
<entity name='new_issue'>
<attribute name='new_issueid'/>
<attribute name='new_name'/>
<attribute name='createdon'/>
<order descending='false' attribute='new_issueid'/>
<filter type='and'>
<condition attribute='new_issueid' operator='eq' value='ddd33910-7c12-e411-a5f0-00155d550f0a'/>
</filter>
<link-entity name = 'new_costtype' alias='ac' to='new_issueid' from='new_costtypeissueid'>
<link-entity name='new_costtobusiness' alias='ad' to='new_costtobusinesscosttypeid' from='new_costtobusinessid'>
<attribute name='new_coststring'/>
</link-entity>
</link-entity>
</entity>
</fetch>Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>OperationStatus</d2p1:key>
<d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>SubErrorCode</d2p1:key>
<d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">
2146233088</d2p1:value>
</KeyValuePairOfstringanyType>
`fetch distinct='true' mapping='logical' output-format='xml-platform'version='1.0'>
<entity name='new_issue'>
<attribute name='new_issueid'/>
<attribute name='new_name'/>
<attribute name='createdon'/>
<order descending='false' attribute='new_issueid'/>
<filter type='and'>
<condition attribute='new_issueid' operator='eq' value='ddd33910-7c12-e411-a5f0-00155d550f0a'/>
</filter>
<link-entity name = 'new_costtype' alias='ac' to='new_issueid' from='new_costtypeissueid'>
<link-entity name='new_costtobusiness' alias='ad' to='new_costtobusinesscosttypeid' from='new_costtobusinessid'>
<attribute name='new_coststring'/>
</link-entity>
</link-entity>
</entity>
</fetch></Message>
<Timestamp>2014-08-13T13:10:53.9593098Z</Timestamp>
[CostToBusiness: CostToBusiness.CostBusiness]
[2db9e3ba-3616-e411-a5f0-00155d550f0a: CostToBusiness.CostBusiness: Update of new_issue]
</TraceText>
</OrganizationServiceFault>
关于消息的最后一部分,很抱歉,由于某种原因,我无法将其全部转换为代码格式
如果我理解正确,您将new_issue作为其他实体的子实体,带有字段以存储new_issue的总成本。在这种情况下,你应该在new_issue上有PostOperation插件(创建/更新/StateChange),你的fetch xml应该是聚合fetch xml,它将搜索所有new_issue,其中查找字段id等于父实体id,然后聚合成本。在Delete的情况下,您必须以稍微不同的方式处理它。HTH