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)

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
    237,878 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
    237,878 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
    237,878 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

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans