【发布时间】:2014-08-12 09:49:33
【问题描述】:
在我工作的公司中,我在 Microsoft Dynamics CRM 2013 中创建了一个名为 Issue 的新实体,在实体 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>";
但是,查询不能返回任何内容,因为以下代码没有被执行。
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 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>
`
对消息的最后一部分感到抱歉,由于某种原因,我终生无法将其全部转换为代码格式
【问题讨论】:
-
需要额外的上下文。代码应该如何执行?它在插件中吗?插件是如何注册的?
-
嗨@Daryl,这是一个插件,它在更新、预操作和同步时注册(预操作,因为插件正在更新字段)谢谢
-
您是否希望插件在用户向业务添加新成本时触发?
-
保存/更新记录时不会触发插件
-
问题与查询有关,因为我在未调用的 foreach 循环中放入了 throw new InvalidPluginExecutionExeception,因此查询必须不返回任何内容
标签: c# plugins dynamics-crm-2013 fetchxml