locked
Question about plugin context in CRM 2011 RRS feed

  • Question

  • Hey guys, I met a problem when tried to Retrieve case in a pre-operation of a "Retireve Cases" Execution.
    I need to share some Variables but it seems that the context are different, so what is the mechannisem of plugin working, and how it the context set?
    Here it is my code:
        public void Execute(IServiceProvider serviceProvider)
        {
          IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));
    
          if (context.InputParameters.Contains("Target")
            && context.InputParameters.Contains("ColumnSet")
            && !context.SharedVariables.Contains("CustomRetrieve"))
          {
            var entity = context.InputParameters["Target"] as EntityReference;
            var colset = context.InputParameters["ColumnSet"] as Microsoft.Xrm.Sdk.Query.ColumnSet;
    
            if (entity != null && entity.LogicalName == "incident" && colset != null)
            {
              if (context.ParentContext == null && !context.ParentContext.SharedVariables.Contains("CustomRetrieve"))
              {
                //context.SharedVariables.Add("asdfasdf", entity.Id + "," + entity.LogicalName + "," + entity.Name);
                context.SharedVariables["CustomRetrieve"] = true;
    
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)
                  serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(
                  context.UserId);
    
                var outEntity = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet(new string[] { "new_caseprivate", "ownerid" }));
    
                //if (!outEntity.Contains("new_caseprivate")) 
    
    
                if (outEntity != null && outEntity.Contains("new_caseprivate") && outEntity.Contains("ownerid"))
                {
                  entity.Id = Guid.Empty;
                }
    
                context.SharedVariables["CustomRetrieve"] = true;
              }
            } 
          }
        }
    
    When i tired to retireve a case, i want to block user's private case to others. so i made a new Retrieve case request and when i get the value of case, i judge if it's avilable for current user, if not. i set the entity's id to guid.empty.
    but the problem is , it's easy to run into a infinite loops here, i tried to use Sharedvariables to mark it. but i failed. cause i cant get the variable. so anynone can help me a little bit with that?
    Friday, May 20, 2011 7:25 AM

All replies

  • Please check this post. http://ms-crm-2011-beta.blogspot.com/2011/04/how-to-pass-parameters-from-one-plugin.html Hope this helps.
    Linkedin : http://in.linkedin.com/in/rammscrm/
    Wednesday, May 25, 2011 8:26 AM