在Dynamics 365中升级Transactioncurrency实体时发生意外错误

时间:2018-08-10 08:20:47

标签: dynamics-crm dynamics-365

我们正在将我们的外部货币系统与Dynamics transactioncurrency实体同步。除了纯粹创建新的其他货币外,我们还需要更新现有的货币,因此此处采用UpsertRequest。示例代码在此处下载:https://code.msdn.microsoft.com/Sample-Quick-start-for-650dbcaa

CrmServiceClient crmServiceClient = new Xrm.Tooling.Connector.CrmServiceClient(connectionString);

Entity newCurrency = new Entity("transactioncurrency", Guid.Parse("FC5EE57F-64E5-45CF-A7D7-5C0616C712FA"));
newCurrency["isocurrencycode"] = "SGD";
newCurrency["currencyname"] = "Singapore Dollar";
newCurrency["currencysymbol"] = "$";
newCurrency["currencyprecision"] = 2;
newCurrency["exchangerate"] = (decimal)1.4102700000;

UpsertResponse response = (UpsertResponse)crmServiceClient.ExecuteCrmOrganizationRequest(new UpsertRequest() { Target = newCurrency });
Console.WriteLine("RecordCreated: {0}.", response.RecordCreated);

但是,与此同时,我们遇到了一些奇怪的错误。假设实体中还不存在SGD或主要ID“ FC5EE57F-64E5-45CF-A7D7-5C0616C712FA”。 通过执行此upsert请求,我们得到以下错误:

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Source      : mscorlib
Method  : HandleReturnMessage
Date    : 8/10/2018
Time    : 3:42:40 PM
Error   : Message: An unexpected error occurred.
ErrorCode: -2147220970
Trace:
Stack Trace     : Server stack trace:
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Execute(OrganizationRequest request)
   at Microsoft.Xrm.Tooling.Connector.CrmServiceClient.CrmCommand_Execute(OrganizationRequest req, String errorStringCheck)
======================================================================================================================
Inner Exception Level 1 :
==OrganizationServiceFault Info=======================================================================================
Error   : System.ArgumentNullException: Value cannot be null.
Parameter name: input
Time    : 8/10/2018 7:42:40 AM
ErrorCode       : -2147220970
Date    : 8/10/2018
Time    : 3:42:40 PM
Trace   : Not Provided
======================================================================================================================

The application terminated with an error.
Object reference not set to an instance of an object.
Press <Enter> to exit.

我们观察到的是:

  • 如果主要标识为“ FC5EE57F-64E5-45CF-A7D7-5C0616C712FA”的货币已经存在,则更新过程将成功完成。
  • 如果将目标主ID更改为Guid.Empty,并且创建过程成功完成,则Dynamics服务将帮助填充ID。但是,这对我们来说并不理想,因为我们需要与外部系统同步。
  • 如果我们将此记录(具有首选guid值)的UpsertRequest更改为CreateRequest,则Create过程成功完成。
  • 相同的upsert模式对其他实体也适用。

那么,将记录上载到transactioncurrency实体时,这是一个bug吗?任何帮助深表感谢!

1 个答案:

答案 0 :(得分:0)

您正在将GUID参考传递给Upsert函数。如果记录的Guid不为空,则该过程可能默认情况下处于更新状态,而不是允许您指定新记录的Guid。取决于Upsert方法的实现,到目前为止,我找不到关于它的任何信息,但是如果您使用upsert,并且您指定的guid为空,操作是否可以正确完成?如果是这种情况,我建议您查看替代键选项,而不要使用向导。

https://mahadeomatre.blogspot.com/2016/10/upsert-request-using-alternative-key.html