我在Update
的{{1}}(pre-op)上有一个插件,其中我正在检索关联的InvoiceDetail
以从中获取更多信息(即: CRM 2016中在发票级别选择的税务概况。
我是这样做的:
Invoice
上面这段特定代码触发了//xrmObjects is an object containing all useful objects in plugins/workflow...
var invoice = RetrieveEntity(xrmObjects.Service, xrmObjects.TracingService, image["invoiceid"] as EntityReference, new ColumnSet("invoiceid", "pricelevelid", "customerid", "opportunityid", "xtc_tax_definition"));
Update
以下是上面调用的方法:
InvoiceDetail
这是public static Entity RetrieveEntity(IOrganizationService service, ITracingService tracingService, EntityReference target, ColumnSet columnSet)
{
Entity entity = new Entity();
try
{
entity = CrmServiceExtensions.ExecuteWithRetry<RetrieveResponse>(service, new RetrieveRequest
{
Target = target,
ColumnSet = columnSet
}).Entity;
}
catch (Exception ex)
{
tracingService.Trace($"Error retrieving {target.LogicalName}: {ex.Message}");
throw;
}
return entity;
}
:
ExecuteWithRetry
我已经验证没有发生任何时髦,InvoiceDetail上的更新消息再次在public static T ExecuteWithRetry<T>(IOrganizationService service, OrganizationRequest request)
where T : OrganizationResponse
{
T response = null;
int i = 0;
// Maximum of five iterations.
while (i < 5)
{
try
{
response = (T)service.Execute(request);
// If the Execute does not throw an Exception, break the loop
break;
}
catch (System.Web.Services.Protocols.SoapException e)
{
// Retry if the SoapException is a "Generic SQL Error",
// otherwise rethrow the SoapException.
// "Generic SQL Error" might indicate a deadlock.
if (e.Detail.InnerText.ToLower().Contains("generic sql error"))
{
++i;
// Wait (sleep thread) for i * 1000 milliseconds.
// So, first iteration waits 1 second,
// while fifth iteration will wait 5 seconds.
System.Threading.Thread.Sleep(i * 1000);
}
else throw;
}
}
if (i >= 5)
{
throw new Exception("ExecuteWithRetry: too many retries");
}
return response;
}
行
我还尝试使用早期绑定和上下文来检索发票,但加载发票的response = (T)service.Execute(request);
方法也做同样的事情....
LoadProperty
我在步骤配置中看不到任何可以执行此操作的内容。有什么想法吗?
答案 0 :(得分:1)
我没有使用LoadProperty
,而是像这样手动检索发票
var invoice = ctx.InvoiceSet.SingleOrDefault(x => x.Id == image.InvoiceId.Id);
而不是:
ctx.LoadProperty(image, "invoice_details");
出于某种原因,LoadProperty
会在子帐单详细信息中触发不需要的更新消息...