Chunchun Wu
Chunchun Wu

Reputation: 36

Unexpected error when upserting transactioncurrency entity in Dynamics 365

We are syncing our external currency system with Dynamics transactioncurrency entity. Instead of purely creating new additional currencies, we also need to update existing ones, so UpsertRequest is adopted here. Sample code is downloaded here: 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);

However, we hit some strange errors while doing so. Let's say neither SGD nor the primary id "FC5EE57F-64E5-45CF-A7D7-5C0616C712FA" exist in the entity yet. By executing this upsert request, we got below error:

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.

What we observed are:

So, is this a bug when upserting records into transactioncurrency entity? Any help is much appreciated!

Upvotes: 1

Views: 619

Answers (1)

Mauro De Biasio
Mauro De Biasio

Reputation: 1146

you are passing a GUID reference to the Upsert function. It's possible that if the Guid of the record is not empty, the process goes in update by default, instead of allowing you to specify the Guid of the new record. Depends on the implementation of the Upsert method, so far i couldn't find any info on it, but if you use upsert, and the guid you specify is empty, does the operation completes correctly? If this is the case i suggest you to look into the alternate keys option instead of use the Guids.

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

Upvotes: 0

Related Questions