Friday, 1 February 2019

Move queue item from one queue to another programmatically in Dynamics 365

This article shows how to add a record from one queue to another.

AddToQueueRequest routeRequest = new AddToQueueRequest
{
        SourceQueueId = queueId.Id,
        Target = new EntityReference(obj.LogicalName, obj.Id),
        DestinationQueueId = userQueueId

};
orgService.Execute(routeRequest);


Sample Code

using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk.Messages;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Metadata.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

namespace CRMCodeHelper
{
class Program
{
private static IOrganizationService service = null;

static void Main(string[] args)
{       

service = ConnectToCRM();

Guid sourceQueueId = new Guid("9b2296-bacb-e811-a962-000d3ab4998c");

Guid destinationQueueId = new Guid("4f7cd6-54c5-e811-a95d-000d3ab49476");

EntityReference Target = 
new EntityReference("phonecall",new Guid("8d408d-c255-4587-9e34-596d496e6738"));

MoveQueueItem(sourceQueueId, destinationQueueId, Target);

}

public static IOrganizationService ConnectToCRM()
{

IOrganizationService organizationService = null;
try
{

   ClientCredentials clientCredentials = new ClientCredentials();

   clientCredentials.UserName.UserName = "<UserName>";

   clientCredentials.UserName.Password = "<Password>";

   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

   organizationService = 
new OrganizationServiceProxy(new Uri("<CRM Organisation Service URL>"), null, clientCredentials, null);

   return organizationService;

  }

catch (Exception ex)
{

 Console.WriteLine("Exception caught - " + ex.Message);

 return organizationService;

}

}

public static void MoveQueueItem(Guid SourceQueueGuId, Guid DestinationQueueGuid, EntityReference ItemToMove)
{

 AddToQueueRequest routeRequest = new AddToQueueRequest
 {

    SourceQueueId = SourceQueueGuId,

    Target = ItemToMove,

    DestinationQueueId = DestinationQueueGuid

 };

   service.Execute(routeRequest);

}
}

}

3 comments:

  1. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to

    (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time.

    Contact him now and thank me later.

    ReplyDelete

Blogger Widgets