locked
help with plugin default user view RRS feed

  • Question

  • hi every body, i have a problem with this plug in, show in article in this site:

    http://a33ik.blogspot.com/2009/06/personal-default-views-manager-for.html

    but, my problem is when press form button save, it show me a error, tipycal microsoft, this is code plugin  

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Sdk.Query;
    using System.Diagnostics;

    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("crm_defaultuserview");
    query.Criteria.AddCondition(new ConditionExpression("crm_userid", ConditionOperator.Equal, context.UserId));
    query.Criteria.AddCondition(new ConditionExpression("crm_entitytypecode", ConditionOperator.Equal, entityname));
    query.ColumnSet =new ColumnSet(new string[] { "crm_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

    // in this if enter always

    if (response.BusinessEntityCollection.BusinessEntities.Count == 0)
       return;

     


    //Identifier of Default View

    Guid defaultviewid = new Guid(((DynamicEntity)response.BusinessEntityCollection.BusinessEntities[0])["crm_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 resultset

    foreach (DynamicEntity de in result.BusinessEntities)
    if (((Key)de["savedqueryid"]).Value.Equals(defaultviewid))

    de["isdefault"] = new CrmBoolean(true);

    else

    de["isdefault"] = new CrmBoolean(false);

    }


    }

    #endregion

    }

    }

    so i debug a code then always enter in this if

    if (response.BusinessEntityCollection.BusinessEntities.Count == 0)
       return;

    in sql-server i see entity crm_defaultuserview, but this is empty, then where save data and when in entity crm_defaultuserview? en this plug in i dont see this save procedure

    thanks i hope we help me

    Monday, October 18, 2010 2:41 PM