Hey Guys,
Looking for some assistance if possible. First time developing with Dynamics and I have written a console app to process records from a csv file and enter them into Dynamics CRM. The code I have written seems to process all the records fine but when I look at the records in CRM once the console app has ran the total records do not equal to the records in the csv file.
The record set I am processing is around 15-20K and I am using the ExportMultipleRequest to process the batches in batches of 1000 due to the maxbatchsize being 1000 by default. Here is my code any help to diagnose the issue woudl be greatly appreciated.
public static void InsertPlanSales() { // Get the CRM connection string CrmServiceClient crmConn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString); IOrganizationService crmService = crmConn.OrganizationServiceProxy; EntityCollection planSalesList = new EntityCollection(); // Create an ExecuteMultipleRequest object. ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest() { // Assign settings that define execution behavior: continue on error, return responses. Settings = new ExecuteMultipleSettings() { ContinueOnError = false, ReturnResponses = true }, // Create an empty organization request collection. Requests = new OrganizationRequestCollection() }; try { string csvPath = ConfigurationManager.AppSettings["localFile"]; //Read the contents of CSV file. var csvRows = File.ReadAllLines(csvPath); //Start at 2nd row as first is headers int startRow = 1; //Loop through the rows in the CSV. for (int i = startRow; i < csvRows.Length; i++) { string currentRow = csvRows[i].Replace("\"", string.Empty); string[] columnValues = currentRow.Split(','); Entity planSaleDetails = new Entity("red_sales"); //Map values to Dynamics fields. planSaleDetails.Attributes["red_anubisnumber"] = columnValues[0]; planSaleDetails.Attributes["red_allocationnumber"] = columnValues[1]; planSaleDetails.Attributes["new_agenttype"] = columnValues[2]; planSaleDetails.Attributes["red_fdtype"] = columnValues[3]; planSaleDetails.Attributes["new_sellername"] = columnValues[6]; planSaleDetails.Attributes["red_sellerhoname"] = columnValues[7]; planSaleDetails.Attributes["red_fdname"] = columnValues[8]; planSaleDetails.Attributes["red_fdhoname"] = columnValues[9]; planSaleDetails.Attributes["red_plannumber"] = columnValues[10]; planSaleDetails.Attributes["red_brander"] = columnValues[11]; planSaleDetails.Attributes["red_applicationtype"] = columnValues[12]; planSaleDetails.Attributes["red_paymenttype"] = columnValues[13]; planSaleDetails.Attributes["red_salestatus"] = columnValues[14]; planSaleDetails.Attributes["red_applicationdate"] = columnValues[15] == string.Empty ? null : (DateTime?)Convert.ToDateTime(columnValues[15]).ToUniversalTime(); planSaleDetails.Attributes["red_startdate"] = columnValues[16] == string.Empty ? null : (DateTime?)Convert.ToDateTime(columnValues[16]).ToUniversalTime(); planSaleDetails.Attributes["red_cancellationdate"] = columnValues[17] == string.Empty ? null : (DateTime?)Convert.ToDateTime(columnValues[17]).ToUniversalTime(); planSaleDetails.Attributes["red_scorecardchannel"] = columnValues[18]; planSaleDetails.Attributes["new_salesvalueatpos"] = columnValues[19] == string.Empty ? null : (Double?)Convert.ToDouble(columnValues[19]); planSaleDetails.Attributes["red_salesvalueatalloc"] = columnValues[20] == string.Empty ? null : (Double?)Convert.ToDouble(columnValues[20]); planSaleDetails.Attributes["red_salestype"] = columnValues[21]; planSaleDetails.Attributes["red_maturitystatus"] = columnValues[22]; planSaleDetails.Attributes["red_plancategory"] = columnValues[23]; planSalesList.Entities.Add(planSaleDetails); } } catch (Exception ex) { Console.WriteLine(ex.Message); } int remainingRecords = planSalesList.Entities.Count(); foreach (var entity in planSalesList.Entities) { CreateRequest createRequest = new CreateRequest { Target = entity }; requestWithResults.Requests.Add(createRequest); remainingRecords--; if (requestWithResults.Requests.Count == 1000 || remainingRecords == 0) { var responseWithResults = crmService.Execute(requestWithResults) as ExecuteMultipleResponse; requestWithResults.Requests.Clear(); Console.WriteLine("{0}.{1}.{2}", "1000 Records Processed", "Remaining Records ", remainingRecords ); } } }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156