plugin from CRM 4.0 to CRM 2011 does not execute RRS feed


All replies

  • there is syntax changes from 4.0 to 2011 are explain in below link



    ms crm

    Thursday, March 7, 2013 3:23 PM
  • I know maybe I am asking too much here....could anybody "transform" this code for the plugin to work  for CRM 2011? I am stuck with it really :(

    using System;
    using System.Collections.Generic;
    using System.Text;using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Sdk.Query;
    namespace InternalPVM
        public class DefaultViewHandler : IPlugin
            #region IPlugin Members
            public void Execute(IPluginExecutionContext context)
                if (context.PrimaryEntityName == EntityName.savedquery.ToString() &&                context.InputParameters.Contains("Query") &&                context.InputParameters["Query"] is QueryExpression)
                    QueryExpression resultExpression = (QueryExpression)context.InputParameters["Query"];
            //I retrieve entity Type code of entity
                    string entityname = ((ConditionExpression)resultExpression.Criteria.Conditions[0]).Values[0].ToString();
                    ICrmService crmsevice = context.CreateCrmService(true);
            //I create a request to retrieve default View for current entity
                    QueryExpression query = new QueryExpression("new_defaultuserview");
                                  query.Criteria.AddCondition(new ConditionExpression("new_userid", ConditionOperator.Equal, context.UserId));
                    query.Criteria.AddCondition(new ConditionExpression("new_entitytypecode", ConditionOperator.Equal, entityname));
                    query.ColumnSet = new ColumnSet(new string[] { "new_defaultview" });
                    RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                    request.ReturnDynamicEntities = true;
                    request.Query = query;
                    RetrieveMultipleResponse response = (RetrieveMultipleResponse)crmsevice.Execute(request);
            //If there are no settings just exit from this method
                    if (response.BusinessEntityCollection.BusinessEntities.Count == 0)
            //Identifier of Default View
                    Guid defaultviewid = new Guid(((DynamicEntity)response.BusinessEntityCollection.BusinessEntities[0])["new_defaultview"].ToString());
                    BusinessEntityCollection result = (BusinessEntityCollection)context.OutputParameters["BusinessEntityCollection"];
            //Scroll all Views one-By-One and Set default View from user Setting to be default in
                    foreach (DynamicEntity de in result.BusinessEntities)
                        if (((Key)de["savedqueryid"]).Value.Equals(defaultviewid))                        de["isdefault"] = new CrmBoolean(true);
                        else                        de["isdefault"] = new CrmBoolean(false);

    thank you,


    Thursday, March 7, 2013 4:25 PM
  • Hi,

    You can see this articles for change your code:



    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.

    Pedro Azevedo Crm Specialist 4.0\2011

    Thursday, March 7, 2013 4:30 PM
  • Are you sure the plugin does not execute, or is it that it doesn't do anything ? The difference is significant - if it doesn't execute then the problem is probably with the plugin registration, whereas if it executes but doesn't do anything, then the problem is probably to do with the code.

    If CRM is OnPremise, then one way to check if the plugin is executing is to attach the Visual Studio debugger

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

    Thursday, March 7, 2013 4:48 PM
  • Hi David,

    this plugin works fine in CRM 4.0. I registered it on CRM 2011 server and it  does not assign my views to the users. I assume it does not execute.

    Do you think the code above should work in CRM 2011 as is? - no changes done based on the links I received from other CRM users?


    Thursday, March 7, 2013 5:03 PM
  • Hi,

    It's seems that you don't use anything unsupported so your plugin should work in CRM 2011. Take a look.

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.

    Pedro Azevedo Crm Specialist 4.0\2011

    Thursday, March 7, 2013 5:14 PM
  • Hi Pedro,

    I enabled trace on the server but there is nothing there.... Also this plugin should populate a field that is mandatory - the Name of the entity and that one is empty even if it looks populated with a value from a picklist... so in this case I get the CRM error message: -  "You must provide a value for Entity Name" and I cannot save my record.

    Any thoughts?


    Thursday, March 7, 2013 5:26 PM
  • Hi again,

    I am still stuck with this problem. Do you have any ideas? I am not sure what to do next to make it work :(


    Thursday, March 7, 2013 8:17 PM
  • Hi,

    Which message and entity are you registering your plugin? The error you mention is giving in user interface? A plugin cannot act in client. Can you give more information about the steps that you want perform.

    Hope this helps.

    Pedro Azevedo Crm Specialist 4.0\2011

    Friday, March 8, 2013 10:12 AM
  • Hi,

    It's in here....personal default view manager: http://a33ik.blogspot.ca/2009/06/personal-default-views-manager-for.html. I am trying to make this work in CRM 2011. It is working in CRM 4.0.

    I did register the plugin with the CRM 2011 registration tool but it seems it does not get executed.

    This code creates an entity child to systemuser entity in which user can select default view for an entity. Then write a plugin which will handle RetrieveMultiple message
    on savedquery entity.

    Friday, March 8, 2013 1:43 PM
  • Hello Alina,

    Actually you don't need any plugins. You have "Set as Default" button at View Ribbon Tab.

    Freelance Developer for Dynamics CRM 4.0/2011

    • Proposed as answer by Philippe LEAL Sunday, March 10, 2013 11:35 AM
    • Marked as answer by AlinaDo123 Tuesday, March 12, 2013 5:20 PM
    Sunday, March 10, 2013 8:23 AM
  • And finally, somebody reads the code!  +1 Awesome to my good friend, Andrii.  The code in your plugin is obsoleted by new features of CRM 2011.  What the code does, is use a collection of custom entities to define the configuration of "Default View" for users.  It sits directly on top of the "savedquery" entity and injects the result of configuration into the "RetrieveMultiple" response. 

    For CRM 4, this would allow you to provide configurable default views.  In CRM 2011, with no additional code, users can assign their default views using the method Andrii describes.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.

    Sunday, March 10, 2013 10:29 PM