none
Unable to add to queue using plugin

    Question

  • Hello Team,

    I tried to add a case when its created in system with queue, but its not working. Below is the code. 

    try
                {
                    IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
                    IOrganizationServiceFactory servicefactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                    IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
                    Entity entCase = new Entity();                
                    EntityCollection entProduct = new EntityCollection();
                    EntityCollection entQueue = new EntityCollection();
    
                    if (context.InputParameters.Contains("Target"))
                    {
                        entCase = (Entity)context.InputParameters["Target"];
                        if (entCase.Attributes.Contains("productid"))
                        {
                            QueryExpression productQuery = new QueryExpression();
                            productQuery.EntityName = "product";
                            productQuery.ColumnSet = new ColumnSet("name");
                            productQuery.Criteria.AddCondition("productid", ConditionOperator.Equal, (Guid)entCase.Attributes["productid"]);
    
                            entProduct = service.RetrieveMultiple(productQuery);
                            if (entProduct.Entities[0].Attributes.Contains("name"))
                            {
                                string Value = entProduct.Entities[0].Attributes["name"].ToString();
                                if (Value == "3G Dataplan Queue")
                                {
                                    QueryExpression queueQuery = new QueryExpression();
                                    queueQuery.ColumnSet = new ColumnSet("queueid");
                                    queueQuery.Criteria.AddCondition("name", ConditionOperator.Equal, Value);
                                    entQueue = service.RetrieveMultiple(queueQuery);
    
                                    AddToQueueRequest addtoQueue = new AddToQueueRequest();
                                    addtoQueue.SourceQueueId = entCase.Id;
                                    addtoQueue.DestinationQueueId = ((EntityReference)entQueue.Entities[0].Attributes["queueid"]).Id;
                                    addtoQueue.Target = new EntityReference(entCase.LogicalName, entCase.Id);
                                    service.Execute(addtoQueue);
                                }
                            }
                            else
                            {
                                entCase.Attributes["description"] = "None of the products coming from Products entity1";
                                service.Update(entCase);
                            }
                        }
                        else
                        {
                            entCase.Attributes["description"] = "None of the products coming from Products entity2";
                            service.Update(entCase);
                        }
                    }
                    else
                    {
                        Console.Write("not working");
                    }
                }
                catch (SoapException soap)
                {
                    throw soap;
                }
                catch (Exception ex)
                {
                    throw ex;
                }

    Help me where is the issue?

    Regards,
    Kumar R

    Friday, July 18, 2014 11:20 AM

All replies

  • Hi Kumar,

    Source queue id should be the queue id and not case id. Please remove the code to set source id ( addtoQueue.SourceQueueId =entCase.Id;) and try.

    HTH!

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" 

    Friday, July 18, 2014 11:39 AM
  • Hi,

    I tried that, but no success.

    Kumar R

    Friday, July 18, 2014 12:31 PM
  • Hi,

    Are you getting any error? Can please explain more?


    Friday, July 18, 2014 12:35 PM
  • Case record is getting created in application and not getting any error message while creating the case record.

    but case is not associating/adding with queue. I am using this logic in MS CRM 2013 online environment.

    Friday, July 18, 2014 1:32 PM
  • Hi Kumar,

    Can you please recheck your product name "3G Dataplan Queue"? Check for extra white spaces and also check lower and upper case.

    If there is any mismatch in case (lower or upper) then "if (Value == "3G Dataplan Queue")" will result in false and AddToQueue code will not get excuted.

    Please check and confirm

    Monday, July 21, 2014 8:12 AM
  • I checked in application, product with name "3G Dataplan Queue" is already exist in application.


    Monday, July 21, 2014 11:01 AM