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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

OData Update Operations in D365Ax7

(0) ShareShare
ReportReport
Posted on by

Hi friends,

                How to update the D365 AX7 customer  form using Odata service(integration).

I have created the new records in customer form using odata like:

string CustomerNumber = "THMF-000013";
Customer customer = new Customer();
DataServiceCollection<Customer> CustomerCollection = new DataServiceCollection<Customer>(Context);
CustomerCollection.Add(customer);
customer.CustomerAccount = CustomerNumber;
customer.Name = "Antony";
customer.CustomerGroupId = "10";
customer.SalesCurrencyCode = "THB";
customer.DataAreaId = "THMF";
customer.AddressCountryRegionId = "AFG";
Context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); 

Please give a suggestion.

Thanks & regards,

Ashwini

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,118 Most Valuable Professional on at

    Your code is creating a new customer, not updating an existing one. If you want to update a customer, first find it (e.g. var cust = context.Customers.Where(c => c.CustomerAccount == "THMF-000013")), change its properties and call SaveChanges().

  • Community Member Profile Picture
    on at

    Hi Martin,

                   Thanks for your response. 

                  when i used this code ,

    string Company = customer.DataAreaId;
    customer.Name = "kim";
    var assetMajorTypeAfterUpdate = Context.Customers.Where(x => x.CustomerAccount == "THMF-000013" && x.DataAreaId == Company).First();
    Context.UpdateObject(customer);
    Context.SaveChanges();
    Console.WriteLine("Asset Major type of ID {0} successfully updated.", assetMajorTypeAfterUpdate.CustomerAccount);

    I am getting this type of error,

    error-in-update.png

  • Martin Dráb Profile Picture
    239,118 Most Valuable Professional on at

    No, you didn't get it. You save the customer to assetMajorTypeAfterUpdate variable, but then you're ignoring it and you're still working with the customer variable.

    Regarding the exception, test the simpler case without the condition for DataAreaId.

  • Community Member Profile Picture
    on at

    Hi martin,

               I used this piece of code,

                " var cust = Context.Customers.Where(c => c.CustomerAccount == "THMF-000013" ).FirstOrDefault();

               Context.UpdateObject(cust);

               Context.SaveChanges();"

    I am getting error like:

    "An unhandled exception of type 'System.InvalidOperationException' occurred in System.Core.dll Additional information: Sequence contains no elements"

    I am not getting the values from customer account its shown as null.

    Thanks & regards,

    Ashwini

  • Martin Dráb Profile Picture
    239,118 Most Valuable Professional on at

    If you mean that cust is null, trying to update it obviously can't work. You miss a condition checking whether the customer was successfully found.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans