I am currently creating trade agreement journals in D365 through an OData endpoint. I am now load testing it as I have to account for creating up to 120,000 journals.
To populate the DataServiceCollection in the below loop is taking around 37 minutes when I would expect it to be taking at most a couple of seconds. I assume it is firing off some NotifcationChanged event when the property is set but I am not sure.
The code I am using is below, which successfully updates a small amount of records.
DataServiceCollection journals = new DataServiceCollection(context);
OpenSalesPriceJournalLine journal;
foreach (var agreement in agreements)
{
journal = new OpenSalesPriceJournalLine();
journals.Add(journal);
journal.DataAreaId = dataAreaId;
journal.TradeAgreementJournalNumber = journalNumber;
journal.LineNumber = index;
journal.PriceApplicableFromDate = fromDate;
journal.ToQuantity = agreement.QUANTITYAMOUNTTO;
journal.Price = agreement.CalculationAmount;
journal.PriceApplicableToDate = toDate;
journal.PriceCurrencyCode = agreement.CURRENCY;
journal.ItemNumber = agreement.ITEMRELATION;
journal.FromQuantity = agreement.QUANTITYAMOUNTFROM;
journal.QuantityUnitSymbol = agreement.UNITID;
journal.SalesPriceQuantity = agreement.PRICEUNIT;
journal.SalesLeadTimeDays = agreement.DeliveryTime;
journal.FixedPriceCharges = agreement.Markup;
journal.WillSearchContinue = (agreement.SearchAgain == 0) ? NoYes.No : NoYes.Yes;
journal.IsGenericCurrencySearchEnabled = (agreement.GenericCurrency) ? NoYes.Yes : NoYes.No;
journal.WillDeliveryDateControlDisregardLeadTime = (agreement.DisregardLeadTime) ? NoYes.Yes : NoYes.No;
journal.AttributeBasedPricingId = agreement.PDSCalculationId;
}
response = context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);
I have tried the following, which is much quicker to create the collection but nothing is being sent to D365
var journalLst = new List();
foreach (var agreement in agreements)
{
journal.DataAreaId = dataAreaId;
journal.TradeAgreementJournalNumber = journalNumber;
journal.LineNumber = index;
journal.PriceApplicableFromDate = fromDate;
journal.ToQuantity = agreement.QUANTITYAMOUNTTO;
journal.Price = (decimal)agreement.CalculationAmount;
journal.PriceApplicableToDate = toDate;
journal.PriceCurrencyCode = agreement.CURRENCY;
journal.ItemNumber = agreement.ITEMRELATION;
journal.FromQuantity = agreement.QUANTITYAMOUNTFROM;
journal.QuantityUnitSymbol = agreement.UNITID;
journal.SalesPriceQuantity = agreement.PRICEUNIT;
journal.SalesLeadTimeDays = agreement.DeliveryTime;
journal.FixedPriceCharges = agreement.Markup;
journal.WillSearchContinue = (agreement.SearchAgain == 0) ? NoYes.No : NoYes.Yes;
journal.IsGenericCurrencySearchEnabled = (agreement.GenericCurrency) ? NoYes.Yes : NoYes.No;
journal.WillDeliveryDateControlDisregardLeadTime = (agreement.DisregardLeadTime) ? NoYes.Yes : NoYes.No;
journal.AttributeBasedPricingId = agreement.PDSCalculationId;
journal.CustomerAccountNumber = (agreement.ACCOUNTCODE == (int)AccountCode.Table) ? agreement.ACCOUNTRELATION : null;
journal.PriceCustomerGroupCode = (agreement.ACCOUNTCODE == (int)AccountCode.Group) ? agreement.ACCOUNTRELATION : null;
journalLst.Add(journal);
}
DataServiceCollection journals = new DataServiceCollection(context);
journals.Load(journalLst);
response = context.SaveChanges();
Any ideas on how to send this data in a performant way would be much appreciated