Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Plugin Create 2 records when executing and execute properly when debugging

$
0
0

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);
}



Viewing all articles
Browse latest Browse all 46379

Trending Articles