microsoft / Dynamics-AX-Integration

Dynamics AX Integration samples and demos.
287 stars 356 forks source link

Batch Update using OData service context #55

Open VPoonguzhali opened 6 years ago

VPoonguzhali commented 6 years ago

Hi, The below code does the batch insert in D365O context.SaveChanges(SaveChangesOptions.PostOnlySetProperties|SaveChangesOptions.BatchWithIndependentOperations);

Is there any option for Batch Update using the OData service??

sk29110 commented 6 years ago

I have the similar question. How can I send Batch update request from javascript?

VPoonguzhali commented 6 years ago

Hi sk29110,

I am not sure about the javascript. Please find the below i have done for update batch request,

Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); foreach(DataRow dataRow in dt.AsEnumerable().ToList()) { var filterquery= ""+ CustomerAccount +" eq '" + dataRow[CustomerAccount]+"'&DataAreaId eq '"+ dataRow["dat"] + "'"; var dataquery = d365.Customers.AddQueryOption("$filter", filterquery); DataServiceCollection objcust = new DataServiceCollection(dataquery); //since the above object creation is inside the foreach each time it will create a separate object and save the values in it. // Pass the respective fields as below objcust[0].SalesCurrencyCode =dataRow[SalesCurrencyCode] ; objcust[0].CustomerGroupId = dataRow[CustomerGroupId] ; objcust[0].DataAreaId = dataRow[DataAreaId] ; objcust[0].Name =dataRow[Name] ; objcust[0].AddressCountryRegionId = dataRow[AddressCountryRegionId] ; } //After this foreach call the below which will update all the customer object in a batch wise context.savechanges();