Thursday, April 1, 2010

CRM 4 N: N Plugin

It’s been a very long time since I have posted anything. I (and our team) have been very busy with a project going on. However there is couple of new things that I have found in CRM that I thought of sharing with you.

You might know this, you might not know this “We cannot write a plugin or a workflow for CRM N: N (many to many) relationship.” This might cause you a lot of issues and when a new record is added to such a relationship you might want to trigger some other event. We certainly came across that situation and tried everything to no avail. Then we found an unsupported customization which was published in Google by Aaron. That was very very helpful. I have pasted the link below.

http://consulting.ascentium.com/blog/crm/Post533.aspx

What we do here is enable both “Association” and “Disassociation” SDK message to the plugin registration tool. Also when enabling this, it would act as a generic plugin which would get fired for the entire N: N relationships in CRM. This is handy. I’m sure that with CRM 5, dynamics team would add this facility also. But for the time being we might have to live with this solution.

After registering the plugin the code needed to capture information is also pasted below. Whatever is here is an extended version of what was pasted in the above link. Thanks again to Aaron.




protected override void PostAssociateEntities(IPluginExecutionContext context)
{
TextWriter textWriter = TextWriter.Synchronized(File.AppendText(@"C:\Temp\PostAssociateEntities.txt"));
if (context.MessageName == "AssociateEntities")
{
if (context.InputParameters.Contains("Moniker1"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker1"];
Guid Moniker1 = EntityMoniker.Id;
string Name = EntityMoniker.Name;
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}

if (context.InputParameters.Contains("Moniker2"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker2"];
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}
textWriter.Close();

}

}

No comments:

Post a Comment

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...