4

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");
    }
}
Dzarek
  • 539
  • 5
  • 9

1 Answers1

2

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.

James Wood
  • 17,286
  • 4
  • 46
  • 89
  • Yeah but also i have plugin that trigger on update invoice (but only for context.depth < 1) and also there are plugins on update and create invoicedetail, which update invoice. I must update my invoice when invoicedetail was updated, but not from code because i have context.depth. So associate trigger was be brilliant but if you say that only work for N:N... – Dzarek Jan 27 '14 at 09:01