RetrieveMultiple Not Trigger on Account view but trigger on advance find

0
70
Forum Post: Change the Filter On option on Opportunity Associated View for Account form


{
public class ViewFilter : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

try
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.Depth > 1) return;
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);

//Synchronous
//could also be QueryByAttribute or FetchExpression
if(context.Mode == 0 && context.MessageName.Equals(“RetrieveMultiple”) && (context.InputParameters.Contains(“Query”)) && (context.InputParameters[“Query”] is QueryExpression))
{

QueryExpression query = (QueryExpression)context.InputParameters[“Query”];

//get calling user’s info
Guid userId = context.InitiatingUserId;

//check team membership
var userQuery = new QueryExpression(“systemuser”)
{
ColumnSet = new ColumnSet(false)
};
var teamLink = userQuery.AddLink(“teammembership”, “systemuserid”, “systemuserid”);
teamLink.LinkCriteria.AddCondition(“teamid”, ConditionOperator.Equal, new Guid(“********-****-****-****-***********”));
userQuery.Criteria.AddCondition(“systemuserid”, ConditionOperator.Equal, userId);
var isMember = service.RetrieveMultiple(userQuery).Entities.Count != 0;
tracingService.Trace(“Is Team Member? ” + isMember);

if(isMember)
{
ConditionExpression access = new ConditionExpression
{
AttributeName = “cust_access”,
Operator = ConditionOperator.Equal,
Values = {true}
};
query.Criteria.AddCondition(access);
}

}

} catch (Exception ex)
{
tracingService.Trace(“ViewFilter Plugin Exception: “+ ex);
}
}
}
}



Source link

Leave a reply

Please enter your comment!
Please enter your name here