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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

RetrieveMultiple Not Trigger on Account view but trigger on advance find

(0) ShareShare
ReportReport
Posted on by 20

Hi

I have a requirement to limit access to data base on security role. So I'm working on a plugin on retrievemultiple message. Basically the plugin check user's security role then add an according filter to the query.  I registered the plugin on retrievemultiple message on contact and account. The plugin is triggered on contact subgrid, view and advance find. But for account, it's triggered on advance find, but not the views.  I read some other posts regarding activity entity using "rollup" message so I think account is also using a different message that's why the plugin is never triggered. If that's the case is there another way to do this?

Thanks

I have the same question (1)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    If you registered plugin on retrieve multiple message plugin should  trigger in the list view  , subgrid  and advanved find or sdk call with retrieve multiple method.I would suggest to write  some trace log to check ,may be filter condition you wrote is not working.

    You can check here sample code - 

    goutamdascrm.wordpress.com/.../restrict-advanced-find-entity-record-based-on-security-role-using-retrieve-multiple-plugin

  • Ambanana Profile Picture
    20 on at

    Thank you Goutam.

    I have trace log in my code. But the code is not trigger when I open the list view. Because there is no plugin trace log generated. If it's code's problem. how come it's triggered and generated plugin trace log when I use advanced find for account entity and the data is properly filter in advanced find.

  • gdas Profile Picture
    50,091 Moderator on at

    Can you please share your code and the screenshot of steps of plugin registration tool.

  • Ambanana Profile Picture
    20 on at

    pastedimage1574630874687v1.png

    pastedimage1574630944979v2.png


    {
    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);
    }
    }
    }
    }

  • Verified answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    I assume you are using Unified Interface and your code above will only work for Classic UI or Advance find.  A retrieve multiple plugin receives  the Query parameter as QueryExpression for classic UI. However, this has been changed for UCI. A retrieve multiple plugin receives FetchExpression as the Query parameter.  You will have to update your code to cater for both UIs. Please see below as to how you could check and have your code to support both Classic UI and UCI.

    ScreenClip-_5B00_258_5D00_.png

    Please have a look at the link below as well

    https://community.dynamics.com/crm/b/dynamicscrmtipoftheday/posts/tip-1236-review-retrievemultiple-plugins-before-migrating-to-unified-interface

  • Ambanana Profile Picture
    20 on at

    I put some log and the Query is Fetch Expression. That's why.

    Thank you for your help!

  • Suggested answer
    Pradeep_Gowda Profile Picture
    on at

    This is a Feature Gap Between UCI and Classic web Version :

    +Plugin execution is not supported against UCI metadata entities in genera, like savedQueryVisualization, userQueryVisualization, savedQuery, useQuery

    + Microsoft has taken this as a feature request and you should soon see this working.

  • Dynamics 365 Sumit Thakran Profile Picture
    110 on at

    Hi Everyone,

    I am also facing same type of issue where Plugin not getting triggered for SavedQuery entity in RetrieveMultiple Message in UCI Mode. In Classic Mode its getting triggered but not in UCI Mode.

    Is it confirmed by Microsoft that its an existing bug in UCI ?

    Thanks

  • AjayPant93 Profile Picture
    15 on at

    Did you find its solution? entity system views are not triggering the plugin but advanced find views are getting updated.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans