locked
How to modify filter condition of a queueitem view dynamically RRS feed

  • Question

  • Simon Hutson says in his blog http://blogs.msdn.com/b/ukcrm/archive/2011/03/10/using-plug-ins-to-modify-views.aspx?Redirected=true that "Every time you access a view in CRM user interface, it causes the CRM platform to execute a query by raising a RetrieveMultiple request. A plug-in that intercepts this request, can modify the query before it is executed by the CRM platform".

    I want to intercept view request of queueitem entity in a plugin and modify it but the problem is there is no RetrieveMultiple message for queueitem entity in PluginRegistration tool. How can I modify filter condition of a queueitem view dynamically?

    Thanks


    • Edited by Indie.Dev Saturday, March 1, 2014 4:01 PM
    Saturday, March 1, 2014 3:58 PM

All replies

  • It may be that the queueitem data is retrieved using the Execute message (this is used for some FetchXml queries), so you could try registering the plugin on the Execute message and see if it fires


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Proposed as answer by Chen Xiong Tuesday, March 4, 2014 5:02 AM
    • Unproposed as answer by Indie.Dev Tuesday, March 4, 2014 5:53 AM
    Sunday, March 2, 2014 7:38 PM
    Moderator
  • Hi David,

    Execute message also does not exist for queueitem entity.

    Monday, March 3, 2014 6:07 AM
  • The Execute message is not tied to a particular entity

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Monday, March 3, 2014 1:36 PM
    Moderator
  • If I am getting you right, you are saying that I should register a plugin step for Execute message and "Primary Entity" text box in the PluginRegistration tool should be left blank so that this step gets registered for all of the entities and in the plugin code I should check whether this execute message is generated by accessing the view of queueitem entity or not.
    • Edited by Indie.Dev Monday, March 3, 2014 4:00 PM
    Monday, March 3, 2014 3:59 PM
  • If I am getting you right, you are saying that I should register a plugin step for Execute message and "Primary Entity" text box in the PluginRegistration tool should be left blank so that this step gets registered for all of the entities and in the plugin code I should check whether this execute message is generated by accessing the view of queueitem entity or not.

    Hi David,

    I tried the apporach quoted above but the plugin registered for Execute message with "Primary Entity" text box set to blank does not executes at all. Then I changed the message to RetrieveMultiple instead of Execute with "Primary Entity" text box again set to blank and this time plugin executed.

    For the second case when plugin executed, context.InputParameters does not contains "Target" but contains "Query" instead. Can you please suggest how can I use context.InputParameters["Query"] to intercept the desired view of queueitem entity in order to change its filter condition?

    Below is the code of my plugin:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Crm.Sdk.Messages;
    
    namespace Plugin.ModifyFilterOfNextHourView
    {
        public class ModifyFilterOfNextHourView : IPlugin
        {
            IPluginExecutionContext context = null;
            IOrganizationServiceFactory serviceFactory = null;
            IOrganizationService service = null;
            OrganizationServiceContext serviceContext = null;
    
            public void Execute(IServiceProvider serviceProvider)
            {
                try
                {
                    context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                    serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
                    serviceContext = new OrganizationServiceContext(service);
    
                    //This if block does not executes
                    if (context.InputParameters.Contains("Target"))
                    {
                        System.Diagnostics.EventLog.WriteEntry("Plugin.Target", "Target");
                    }
    
                    //This if block executes
                    if (context.InputParameters.Contains("Query"))
                    {
                        System.Diagnostics.EventLog.WriteEntry("Plugin.Query", "Query");
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException("Plugin.ModifyFilterOfNextHourView: " + ex.ToString());
                }
            }
        }
    }



    • Edited by Indie.Dev Tuesday, March 4, 2014 5:53 AM
    Tuesday, March 4, 2014 5:50 AM