Hi Toten,
RetrieveMultiple plugin will trigger every time CRM loads any Contact subgrid. This could be the contact home page grid, subgrid in any other entity, advance find query or any other associated view etc.
You cannot restrict this based on any specific entity. However, you can have the following workaround to achieve your requirement -
On Contact Entity:
1. Create a new field say 'new_viewforaccount'.
2. Create a new view say 'Account Subgrid View'
3. Customize it as per your needs and in addition to that, add another condition as "View For Account Field" does not contain data.
On Account Entity
4. Use this view on the Contact subgrid.
Once done, publish your customization.
Update your plugin code as follows
----------------------------
if (context.MessageName == "RetrieveMultiple" && context.InputParameters.Contains("Query") && context.InputParameters["Query"] is QueryExpression)
{
QueryExpression qe = (QueryExpression)context.InputParameters["Query"];
if (qe.EntityName == "contact")
{
var runLogic = false;
var CE = qe.Criteria.Conditions.ToList();
foreach (var condition in CE)
{
if (condition.AttributeName == "new_viewforaccount")
{
runLogic = true;
}
}
if (runLogic)
{
Entity ent = new Entity("task");
ent["subject"] = "From Plugin";
service.Create(ent);
}
}
}
-----------------------------