I'm trying to update a vendor via the Odata endpoint in d365 F&O, version 10.0.13. This is a Contoso environment. I've tried several different ways to arrange the code but, I'm getting one of two errors when using the SaveChanges() method.
Here's the code - I'm deliberately not updating anything in the Vendor. I'm just passing back the same object that I got for the Odata endpoint but, I still get an error:
in class constructor:
Uri oDataUri = new Uri(AXURL, UriKind.Absolute);
AXResources = new Microsoft.Dynamics.DataEntities.Resources(oDataUri);
AXResources.SendingRequest2 = new EventHandler(delegate (object sender, SendingRequest2EventArgs e)
{
e.RequestMessage.SetHeader("Authorization", GetAuthHeader());
});
AXResources.BuildingRequest = (sender, e) =>
{
var uriBuilder = new UriBuilder(e.RequestUri);
var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query);
paramValues.Add("cross-company", "true");
uriBuilder.Query = paramValues.ToString();
e.RequestUri = uriBuilder.Uri;
};
var query = AXResources.Vendors.Where(v => v.VendorAccountNumber == "1002");
DataServiceCollection updatedVendors = new DataServiceCollection(query, TrackingMode.None);
foreach (Vendor vendor2 in updatedVendors)
{
if (vendor2.VendorAccountNumber == "1002")
{
AXResources.UpdateObject(vendor2);
}
}
AXResources.SaveChanges();//"update not allowed for field 'VendorExceptionGroupId'"
//AXResources.SaveChanges(SaveChangesOptions.PostOnlySetProperties); //"Must be used with DataServiceCollection"
//AXResources.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset); //"update not allowed for field 'VendorExceptionGroupId'"
I've tried this in Visual Studio 2019 and 2017 using the V4 Odata client as well as the new Odata service generator that is still in Beta - both get the same results.
I also got similar errors when trying to update a customer.
What am I missing?