web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Insert data in C# via entities - Exchange rates

(0) ShareShare
ReportReport
Posted on by

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 !

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Srini Ramidi Profile Picture
    2 on at

    Hello,

    Seems like a bug, Other users got similar errors on other entities.  As mentioned in the post setting AllowEdit=Yes on the EndDate field might help.

    community.dynamics.com/.../204478

    Best,

    Srini

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans