Hello,
I am trying to use an external application to connect to D365 in C# to insert exchange rates via based on the Github file example :
https://github.com/Microsoft/Dynamics-AX-Integration
I am able to connect and use the sample queries.
I tried to create my own methods to insert exchange rates :
public static void CreateExchangeRates(Resources d365)
{
ExchangeRate xRate;
xRate = new ExchangeRate()
{
FromCurrency = "EUR",
ToCurrency = "GBP",
Rate = 0.9999M,
RateTypeName = "Default",
StartDate = new DateTime(2017, 11, 15),
ConversionFactor = ODataUtility.Microsoft.Dynamics.DataEntities.ExchangeRateDisplayFactor.One
};
// Create
d365.AddToExchangeRates(xRate);
d365.SaveChanges();
Console.WriteLine(string.Format("Done"));
}
When I call this method, it refuses my insert because I am not allowed to set the value EndDate. Enddate is not allowed to be set as its handled by the system. How can i handle the "mapping" to not try to set the endDate?
This is the error that i get :
Microsoft.OData.Client.DataServiceRequestException occurred
HResult=0x80131509
Message=An error occurred while processing this request.
Source=Microsoft.OData.Client
StackTrace:
at Microsoft.OData.Client.SaveResult.HandleResponse()
at Microsoft.OData.Client.BaseSaveResult.EndRequest()
at Microsoft.OData.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
at ODataConsoleApplication.QueryExamples.CreateExchangeRates(Resources d365) in C:\**********\Dynamics-AX-Integration-master\ServiceSamples\ODataConsoleApplication\QueryExamples.cs:line 45
at ODataConsoleApplication.Program.Main(String[] args) in C:\***********\Dynamics-AX-Integration-master\ServiceSamples\ODataConsoleApplication\Program.cs:line 37
Inner Exception 1:
DataServiceClientException: {
"error":{
"code":"","message":"An error has occurred.","innererror":{
"message":"insert not allowed for field 'EndDate'","type":"Microsoft.Dynamics.Platform.Integration.Services.OData.ODataSecurityException","stacktrace":" at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateProcessor.CreateEntity_Save(ChangeOperationContext context, ChangeInfo changeInfo)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.<>c__DisplayClass5_0.<CreateEntity>b__1(ChangeOperationContext context)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.ExecuteActionsInCompanyContext(IEnumerable`1 actionList, ChangeOperationContext operationContext)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.TrySave(ChangeOperationContext operationContext)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.SaveChanges()\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataDelegatingHandler.<SaveChangesAsync>d__2.MoveNext()"
}
}
}
Thank you in advance for your kind help !