web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Retrieve Multiple plugin

migsbeja Profile Picture migsbeja 655

The other day I was doing a development that would require modifying the query to a determined entity so that the users wouldn’t see some records if the users didn’t have the role for.

After a bit of research, I’ve done this plugin that is very useful to hide the info.

Message: RetrieveMultiple, Pre-Validation

if (context.Mode == 0 && context.Stage == 10 && context.MessageName.Equals("RetrieveMultiple"))
{
	if (context.InputParameters.Contains("Query"))
	{
		if (context.InputParameters["Query"] is QueryExpression)
		{
			if (!UserHasRole(context.InitiatingUserId, "role", service))
			{
				QueryExpression objQueryExpression = (QueryExpression)context.InputParameters["Query"];

				ConditionExpression condition= new ConditionExpression()
				{
					AttributeName = "statuscode",
					Operator = ConditionOperator.In,
					Values = { 2 }
				};

				objQueryExpression.Criteria.AddCondition(condition);
			}
		}
	}
}

Update:

Message: Retrieve Multiple, Post-Operation

In this next example I’m removing information from the columns, in this case, it was the description and subject from Email entity.
Thanks to Aileen Gusni, in this post that she explains how to change a column value, I’ve adapted to my requirement:

IOrganizationService service = localContext.OrganizationService;
var context = localContext.PluginExecutionContext;

if (context.OutputParameters.Contains("BusinessEntityCollection"))
{
	var retrievedResult = (EntityCollection)context.OutputParameters["BusinessEntityCollection"];
	
	foreach (Entity entity in retrievedResult.Entities)
	{
		if (entity.Contains("description"))
			entity.Attributes.Remove("description");

		if(entity.Contains("subject"))
			entity.Attributes.Remove("subject");
	}
}

I post this simple code, but what I was using was filtering the information from determined security roles, i.e., I was checking if the user had the required security role to view the information.

Hope it helps!


Filed under: C#, Dynamics CRM

This was originally posted here.

Comments

*This post is locked for comments