Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin Create 2 records when executing and execute properly when debugging

(0) ShareShare
ReportReport
Posted on by 3,618

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


*This post is locked for comments

  • Suggested answer
    saadzag Profile Picture
    1,145 on at
    RE: Plugin Create 2 records when executing and execute properly when debugging

    Hi,

    I think you dont have the same DLL version deployed and the in you visual studio(where you debug).

    Check if you dont have two steps registered.

    Regards,

    Saad

  • st738407 Profile Picture
    227 on at
    RE: Plugin Create 2 records when executing and execute properly when debugging

    From the sounds of your description it probably is not this, but just incase.  We had a similar issue in the past and our issue was due to our plugin triggering more than once.  Since I do not see your code looping back to the parent I do not think that is the issue, but in the off chance it is I'd rather provide you with a nonsolution than not say anything.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans