在我正在工作的公司内,我在Microsoft Dynamics CRM 2013中创建了一个名为Issue的新实体,在实体问题中有一个子网格,用户可以从实体Cost To Business添加记录。
目的是用户在需要时添加记录。我现在使用带有C#插件的FetchXML查询,以便我可以检索与子网格中的每个记录相关的成本属性,以便我可以填充总成本字段。
到目前为止,我有以下查询
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>";
但是,由于以下代码未执行,因此Query无法返回任何内容。
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 = "";
}
}
有没有人有理由/建议为什么会这样? 提前致谢
更新
详细信息从下载日志中抛出新的InvalidPluginExecutionExeption
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>
`
对于邮件的最后一部分感到抱歉,因为某些原因,我无法将其全部转换为代码格式
答案 0 :(得分:0)
如果我理解正确,您将new_issue作为某个其他实体的子实体,其中包含来自new_issue的聚合成本的字段。 在这种情况下,你应该在new_issue上插入PostOperation(Create / Update / StateChange),你的fetch xml应该是聚合fetch xml,它将搜索所有new_issue,其中lookup字段id等于父实体ID,然后聚合成本。如果是删除,您必须以稍微不同的方式处理它。 HTH