Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Record Visibility by Field Value

(0) ShareShare
ReportReport
Posted on by 15

Hello, Would it be possible to hide records based on a field value?, I have a user who must only access records that contains a certain product. 

  • vignesh.crm Profile Picture
    vignesh.crm 40 on at
    RE: Record Visibility by Field Value

    If your registering your plugin in post operation, you need to change your code as below,

    EntityCollection leadColl = (EntityCollection)context.OutputParameters["BusinessEntityCollection"];

    instead of 

     QueryExpression leadquery= (QueryExpression)context.InputParameters["Query"];

  • MRic Profile Picture
    MRic 15 on at
    RE: Record Visibility by Field Value

    Yes, I tried also doing it on Post Operation to see if it fixes it but still no luck

  • vignesh.crm Profile Picture
    vignesh.crm 40 on at
    RE: Record Visibility by Field Value

    Plugin registered in Synchronous, Pre Operation right ?

  • MRic Profile Picture
    MRic 15 on at
    RE: Record Visibility by Field Value

    Yeah I already debugged it , no error whatsoever

  • vignesh.crm Profile Picture
    vignesh.crm 40 on at
    RE: Record Visibility by Field Value

    If your view is for displaying LEAD records, your code should work. Did you try debugging it ? Do you get any error on loading view ?

  • MRic Profile Picture
    MRic 15 on at
    RE: Record Visibility by Field Value

    Not on subgrid but on System Views, For now I only need it on leads

  • vignesh.crm Profile Picture
    vignesh.crm 40 on at
    RE: Record Visibility by Field Value

    You're trying to execute this plugin in subgrid which contains LEAD records ? Can you please mention your requirement with exact entity names ?

  • MRic Profile Picture
    MRic 15 on at
    RE: Record Visibility by Field Value

    I have registered the plugin but its not working. Here is my code for reference.

    Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)

               serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

               IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

               if (context.InputParameters.Contains("Query") && context.InputParameters["Query"] is QueryExpression)

               {

                   QueryExpression leadquery= (QueryExpression)context.InputParameters["Query"];

                   if (leadquery.EntityName == "lead") // Add your entity logical name

                   {

                       if (context.UserId == new Guid(userguidhere))

                       {

                           ConditionExpression condition = new ConditionExpression("new_product", ConditionOperator.Equal, new Guid(productguidhere));

                           leadquery.Criteria.AddCondition(condition);

                       }        

                   }

               }

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,231 on at
    RE: Record Visibility by Field Value

    As suggested above you could achieve this by plugin only.

    Create and deploy plugin on "RetrieveMultiple" message.

    Please refer below sample code for reference: 

    if(context.InputParameters.Contains("Query") && context.InputParameters["Query"] is QueryExpression)
                        {
                            QueryExpression contactQ = (QueryExpression)context.InputParameters["Query"];
                            if (contactQ.EntityName == "contact") // Add your entity logical name
                            {
                                if (isUserInRole)
                                    return;
                                else
                                {
                                    //sample code
                                    ConditionExpression condition1 = new ConditionExpression("ownerid", ConditionOperator.Equal, context.UserId);
                                    ConditionExpression condition2 = new ConditionExpression("statuscode", ConditionOperator.NotEqual, 809020002);
                                    contactQ.Criteria.AddCondition(condition1);
                                    contactQ.Criteria.AddCondition(condition2);
                                }
                            }
                        }

  • Suggested answer
    vignesh.crm Profile Picture
    vignesh.crm 40 on at
    RE: Record Visibility by Field Value

    You can try with Retrieve Multiple plugin.

    Get the context as below,

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

    ConditionExpression condition = new ConditionExpression(“new_product”, ConditionOperator.Equal, {productid});

    targetQuery.Criteria.AddCondition(condition);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans