Tag Cloud

CRM 2011 (161) CRM 4.0 (144) C# (116) JScript (109) Plugin (92) Registry (90) Techpedia (77) PyS60 (68) WScript (43) Plugin Message (31) Exploit (27) ShellCode (26) FAQ (22) JavaScript (21) Killer Codes (21) Hax (18) VB 6.0 (17) Commands (16) VBScript (16) Quotes (15) Turbo C++ (13) WMI (13) Security (11) 1337 (10) Tutorials (10) Asp.Net (9) Safe Boot (9) Python (8) Interview Questions (6) video (6) Ajax (5) VC++ (5) WebService (5) Workflow (5) Bat (4) Dorks (4) Sql Server (4) Aptitude (3) Picklist (3) Tweak (3) WCF (3) regex (3) Config (2) LINQ (2) PHP (2) Shell (2) Silverlight (2) TSql (2) flowchart (2) serialize (2) ASHX (1) CRM 4.0 Videos (1) Debug (1) FetchXml (1) GAC (1) General (1) Generics (1) HttpWebRequest (1) InputParameters (1) Lookup (1) Offline Plug-ins (1) OutputParameters (1) Plug-in Constructor (1) Protocol (1) RIA (1) Sharepoint (1) Walkthrough (1) Web.config (1) design patterns (1) generic (1) iframe (1) secure config (1) unsecure config (1) url (1)

Pages

Sunday, April 07, 2013

Route an Incident from a User to a Queue

The following code example shows how to route an incident from a user's Work In Progress (WIP) queue into a public queue. Similar code could be used to route an incident from a public queue into a WIP queue.


using System;
using CrmSdk;
using Microsoft.Crm.Sdk.Utility;

namespace Microsoft.Crm.Sdk.HowTo
{
public class HowToRoute
{
static void Main(string[] args)
{
// TODO: Change the server URL and organization to match your Microsoft
// Dynamics CRM Server and Microsoft Dynamics CRM organization.
HowToRoute.Run("http://localhost:5555", "CRM_SDK");
}

public static bool Run(string crmServerUrl, string orgName)
{
bool success = false;

try
{
// Set up the CRM Service.
CrmService service = CrmServiceUtility.GetCrmService(crmServerUrl, orgName);

// Get the ID of the system user.
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest);

#region Setup Data Required for this Sample
// Create a new customer account.
account myAccount = new account();
myAccount.name = "A Bike Store";
Guid accountID = service.Create(myAccount);

// Create a new subject.
subject mySubject = new subject();
mySubject.title = "Bicycles";
Guid subjectID = service.Create(mySubject);

// Create a new incident.
incident incident = new incident();

Customer myCustomer = new Customer();
myCustomer.Value = accountID;
myCustomer.type = EntityName.account.ToString();
incident.customerid = myCustomer;

Lookup subjectLookup = new Lookup();
subjectLookup.Value = subjectID;
subjectLookup.type = EntityName.subject.ToString();
incident.subjectid = subjectLookup;

incident.title = "Broken Chain";
Guid incidentID = service.Create(incident);

// Create a new public Bicycle Cases queue.
queue publicQueue = new queue();

Lookup businessLookup = new Lookup();
businessLookup.Value = user.BusinessUnitId;
businessLookup.type = EntityName.businessunit.ToString();
publicQueue.businessunitid = businessLookup;

Lookup userLookup = new Lookup();
userLookup.Value = user.UserId;
userLookup.type = EntityName.systemuser.ToString();
publicQueue.primaryuserid = userLookup;

Picklist plist = new Picklist();
plist.name = "Public";
plist.Value = 1;
publicQueue.queuetypecode = plist;

publicQueue.name = "Bicycle Cases";
Guid publicQueueID = service.Create(publicQueue);
#endregion

// Find the WIP queue for the user who currently owns the incident.
// The queue type code for a WIP queue is 3.
QueryByAttribute query = new QueryByAttribute();
// Be aware that using AllColumns may adversely affect
// performance and cause unwanted cascading in subsequent
// updates. A best practice is to retrieve the least amount of
// data required.
query.ColumnSet = new AllColumns();
query.EntityName = EntityName.queue.ToString();
query.Attributes = new string[] { "primaryuserid", "queuetypecode" };
query.Values = new string[] { user.UserId.ToString(), "3" };
BusinessEntityCollection results = service.RetrieveMultiple(query);

queue wipQueue = (queue)results.BusinessEntities[0];

// Create a Target object that refers to the incident.
TargetQueuedIncident target = new TargetQueuedIncident();
// SDK:target.EntityId = new Guid("A0F2D8FE-6468-DA11-B748-000D9DD8CDAC");
target.EntityId = incidentID;

// Route the incident from the WIP queue to the public queue.
RouteRequest route = new RouteRequest();
route.Target = target;
route.RouteType = RouteType.Queue;
// SDK:route.EndpointId = new Guid("A0F2D8FE-6468-DA11-C748-000D9DD8CDAC");
route.EndpointId = publicQueueID;
// SDK:route.SourceQueueId = new Guid("A0F2D8FE-6468-DA11-D748-000D9DD8CDAC");
route.SourceQueueId = wipQueue.queueid.Value;

RouteResponse routed = null;
routed = (RouteResponse)service.Execute(route);

#region check success

if (routed != null) success = true;

#endregion

#region Remove Data Required for this Sample

service.Delete(EntityName.incident.ToString(), incidentID);
service.Delete(EntityName.queue.ToString(), publicQueueID);
service.Delete(EntityName.subject.ToString(), subjectID);
service.Delete(EntityName.account.ToString(), accountID);

#endregion
}
catch (System.Web.Services.Protocols.SoapException ex)
{
Console.WriteLine(String.Format("{0}. {1}", ex.Message, ex.Detail.InnerText));
}

return success;
}
}
}

No comments: