locked
Assign Case to Queue (through Workflow) RRS feed

  • Question

  • Hi All

    I have created Plugin to hide queue from user view. (this works perfect - all queues except user queue for time being)
    Message : Retrtieve Multiple
    Entity  : Queue
    Stage  : Post

    I face problem while assigning case to any queue through workflow. I tried assigning it manually (out of box functionality), it works good. Below is the error I obtained in workflow.

    Workflow paused due to error: Unhandled Exception: System.Web.Services.Protocols.SoapException: Server was unable to process request. Detail: <detail><error>  <code>0x80040216</code>  <description>An unexpected error occurred.</description>  <type>Platform</type> </error></detail>  at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)  at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)  at Microsoft.Crm.SdkTypeProxy.CrmService.RetrieveMultiple(QueryBase query)  at Microsoft.Crm.Asynchronous.SdkTypeProxyCrmServiceWrapper.RetrieveMultiple(QueryBase query)  at Microsoft.Crm.Workflow.Services.AssignActivityService.FindUserQueueId(AssignActivity assignActivity, ICrmService crmService, Guid contextUserId, Int32 queueTypeCode)  at Microsoft.Crm.Workflow.Services.AssignActivityService.HandleOrRoute(AssignActivity assignActivity, ICrmService crmService, Guid contextUserId)  at Microsoft.Crm.Workflow.Services.AssignActivityService.Execute(ActivityExecutionContext executionContext, AssignActivity assignActivity)  at Microsoft.Crm.Workflow.Activities.AssignActivity.Execute(ActivityExecutionContext executionContext)  at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)  at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)  at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)  at System.Workflow.Runtime.Scheduler.Run()

    While I disable or unregister the plugin the workflow process runs well. below is the plugin peice of code to hide queue.
    I am adding the BusinessEntities of queue type 2 or 3 (user WIP & improgress queue) to BusinessEntityCollection and overriding context.OutputParameters

    if (queueType != 1)
    {
     targetBusinessEntityCollection.BusinessEntities.Add(objBusinessEntity);
    }
    context.OutputParameters.Properties[ParameterName.BusinessEntityCollection] = targetBusinessEntityCollection;


    Kindly let me know if anyone faced the issue.

    Thanks & Regards
    Vinoth

    Thursday, September 9, 2010 12:49 PM

Answers

  • Hi Mayank

    Hope you understood wrongly. I am hiding all queues except user queue.

    Anyways thanks for your support. The issues is solved.

    The plugin was called asyncronously when I assign case to queue. Filtering CallerOrigin and Depth in plugin solved my issue.

    Thanks & Regards
    Vinoth

    Friday, September 10, 2010 11:39 AM

All replies

  • Hi Vinod,

    why you are hiding queue type 2 and 3 from user these are User's Inprogress and Assign Queue which surely should be (logically) visible to user...

    I guess the reason your filter might not work for 2 & 3 type is that context query might not have business unit id as peremater...

    we have the hide queue plug and we hide only queue type of 1, following is full code for your referance for the same..

    #region IPlugin Members
    
        /// <summary>
        /// Execute method of plug-in
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IPluginExecutionContext context)
        {
          //System.Diagnostics.Debugger.Launch();
    
          // Exit if any of the following conditions are true:
          // 1. plug-in is running offline
    
          if (context.IsExecutingInOfflineMode.Equals(true))
          {
            return;
          }
          // 2. plug-in is not running synchronously
          if (!context.Mode.Equals(0))
          {
            return;
          }
          // 3. plug-in is not running on the 'Queue' entity
          if (!string.IsNullOrEmpty(context.PrimaryEntityName))
          {
            if (!context.PrimaryEntityName.Equals(EntityName.queue.ToString()))
            {
              return;
            }
          }
          // 4. plug-in is not running on the 'RetrieveMultiple' event
          if (!string.IsNullOrEmpty(context.MessageName))
          {
            if (!context.MessageName.Equals("RetrieveMultiple"))
            {
              return;
            }
          }
          // 5. plug-in is not running on the 'pre-stage' event
          if (!context.Stage.Equals(10))
          {
            return;
          }
    
    
          //Check that the InputParameters property bag is not NULL
          if (context.InputParameters.Properties != null)
          {
            foreach (PropertyBagEntry item in context.InputParameters.Properties)
            {
              //Check that a QueryExpression object exists in th property bag	
              if (item.Name == "Query")
              {
                //Get each ConditionExpression from the QueryExpression
                Microsoft.Crm.Sdk.Query.QueryExpression queryExpression = item.Value as Microsoft.Crm.Sdk.Query.QueryExpression;
    
                if (queryExpression != null)
                {
                  if (queryExpression.Criteria != null)
                  {
                    //check if criteria condition exists then go ahed
                    if (queryExpression.Criteria.Conditions != null)
                    {
                      foreach (Microsoft.Crm.Sdk.Query.ConditionExpression conditionExpression in queryExpression.Criteria.Conditions)
                      {
                        //Is the ConditionExpression the one we want to replace 'queuetypecode = 1'
                        if ((conditionExpression.AttributeName == "queuetypecode") &&
                          (conditionExpression.Operator == Microsoft.Crm.Sdk.Query.ConditionOperator.Equal) &&
                          (conditionExpression.Values[0].ToString() == "1"))
                        {
                          //Delete the ConditionExpression
                          queryExpression.Criteria.Conditions.Remove(conditionExpression);
                          //Replace it with a new FilterExpression
                          queryExpression.Criteria.Filters.Add(newFilterExpression(context));
                          break;
                        }
    
                      }
                    }
                  }
                }
    
    
              }
            }
          }
        }
        #endregion
    
        /// <summary>
        /// This method replaces the existing filter of queue view
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public FilterExpression newFilterExpression(Microsoft.Crm.Sdk.IPluginExecutionContext context)
        {
          // Execute the request.
          ICrmService incService = context.CreateCrmService(true);
    
          ConditionExpression condition1 = new ConditionExpression();
          condition1.AttributeName = "queuetypecode";
          condition1.Operator = ConditionOperator.Equal;
          condition1.Values = new object[] { "1" };
    
          ConditionExpression condition2 = new ConditionExpression();
          condition2.AttributeName = "businessunitid";
          condition2.Operator = ConditionOperator.In;
          condition2.Values = GetBusinessChildList(incService, context.BusinessUnitId.ToString());
          //condition2.Values = GetChildBusinessUnitIds(context);
    
    
    
          FilterExpression filterExpression = new FilterExpression();
          filterExpression.FilterOperator = LogicalOperator.And;
          //filterExpression.Conditions =// new ConditionExpression[] { condition1, condition2 };
          filterExpression.Conditions.Add(condition1);
          filterExpression.Conditions.Add(condition2);
    
          return filterExpression;
    
        }
    
    
        /// <summary>
        /// returns business unit list 
        /// </summary>
        /// <param name="incService"></param>
        /// <param name="businessunitId"></param>
        /// <returns></returns>
        private object[] GetBusinessChildList(ICrmService incService, string businessunitId)
        {
          string[] returnChildList = new string[] { };
    
          string returnList = businessunitId;//"77EB195C-845D-DE11-BC3E-0019BBD31BFE";
    
          //condition2.Values = new object[] { "77EB195C-845D-DE11-BC3E-0019BBD31BFE", "70EB195C-845D-DE11-BC3E-0019BBD31BFE" };
          string newList = GetChildBusinessUnitIds(businessunitId, incService, returnList);
    
          returnChildList = newList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
    
          object[] ObjectChildList = new object[returnChildList.Length];
    
          for (int i = 0; i < returnChildList.Length; i++)
          {
            ObjectChildList[i] = returnChildList[i];
          }
          return ObjectChildList;
        }
    
        /// <summary>
        /// Gets all child business unit based on input business unit id
        /// </summary>
        /// <param name="businessId"></param>
        /// <param name="incService"></param>
        /// <param name="returnList"></param>
        /// <returns></returns>
        private string GetChildBusinessUnitIds(string businessId, ICrmService incService, string returnList)
        {
    
    
    
          QueryExpression query = new QueryExpression();
          query.ColumnSet = new AllColumns();
    
          query.EntityName = EntityName.businessunit.ToString();
          FilterExpression filter = new FilterExpression();
          query.Criteria = filter;
    
          ConditionExpression hasBusinessParentId = new ConditionExpression();
          filter.Conditions.Add(hasBusinessParentId);
    
          hasBusinessParentId.AttributeName = "parentbusinessunitid";
          hasBusinessParentId.Operator = ConditionOperator.Equal;
          hasBusinessParentId.Values = new string[] { businessId };
    
    
          // Retrieve the contact.
          RetrieveMultipleRequest req = new RetrieveMultipleRequest();
          req.Query = query;
          req.ReturnDynamicEntities = false;
    
          // Execute the request.
          //ICrmService service = context.CreateCrmService(true);
    
          RetrieveMultipleResponse res
            = (RetrieveMultipleResponse)incService.Execute(req);
    
          //int i =0;
          if (res.BusinessEntityCollection.BusinessEntities.Count >= 1)
          {
    
            businessunit myBusinessunit = null;
            foreach (BusinessEntity be in res.BusinessEntityCollection.BusinessEntities)
            {
              //i = i + 1;
              myBusinessunit = (businessunit)be;
    
              returnList = GetChildBusinessUnitIds(myBusinessunit.businessunitid.Value.ToString(), incService, returnList);
              //returnChildList[i] = context.BusinessUnitId;
              returnList = returnList + "," + myBusinessunit.businessunitid.Value.ToString();
            }
          }
    
          //returnChildList = returnList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
    
          return returnList;
    
        }
      }
    

    MayankP My Blog My twitter
    Thursday, September 9, 2010 12:58 PM
  • Hi Mayank

    Hope you understood wrongly. I am hiding all queues except user queue.

    Anyways thanks for your support. The issues is solved.

    The plugin was called asyncronously when I assign case to queue. Filtering CallerOrigin and Depth in plugin solved my issue.

    Thanks & Regards
    Vinoth

    Friday, September 10, 2010 11:39 AM