Following piece of code needed simply to create a records in CRM when an order is posted. It works well while debugging. But when I stop profiling and let the plugin to execute it executed well and creates couple of records instead of one. Not sure, what is the problem with this snippet, any suggestion to dig out the problem?
private static void createOrderStatusHistory(IOrganizationService service,string status, Guid ownerId, Guid orderId) { Entity osHistory = new Entity("new_statushistory"); //new_orderstatus if (status == "Muni") { osHistory["new_orderstatus"] = "Municipals Ordered"; } else { osHistory["new_orderstatus"] = "Abstract Ordrered "; } osHistory["new_orderstatuschangedate"] = DateTime.Now; osHistory.Attributes.Add("ownerid", new EntityReference("systemuser", ownerId)); osHistory.Attributes.Add("new_assignedto", new EntityReference("systemuser", ownerId)); osHistory.Attributes.Add("new_orderid", new EntityReference("salesorder", orderId)); service.Create(osHistory); }