pluginstriggerscrmassociate

Plugin dose not trigger on associate 1:N in CRM 2011


I have two system entities: invoice and invicedetail.

In system exist association 1:N - invoice_details (parent: invoice, child: invoicedetail).

I go to invoice details, next go to Products section (invoicedetail) and add new product. Now this product and invoice is associate but my plugin not triggered ;/

I registered my plugin on associate (parent and child entity are empty in plugin registration tool, execution is POST-Operation).

Code:

if(context.Message == "Associate")
{
    //but plugin not go here - it's not trigger on associate ;/
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
    {
        entityRef = (EntityReference)context.InputParameters["Target"];
        entity = service.Retrieve("invoice", entityRef.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet("invoiceid", "numberOfSomething"));
    }
    else
    {
        throw new Exception("excep");
    }
}

Solution

  • I believe associate is used for many to many. Try registering your plugin on the update and create of invoicedetail. You will probably want to add filtering attributes to the update so it only fires when the invoice lookup on the invoicedetail changes. Then add a check to only perform your logic when the invoice lookup is set.