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 14, 2013

Route an Incident from a User to a Queue

The following code example demonstrates how to route an incident from a user's work-in-progress queue to another queue.


   1:  //# Route an Incident from a User to a Queue 

   2:  using System;

   3:  using CrmSdk;

   4:  using Microsoft.Crm.Sdk.Utility;

   5:   

   6:  namespace Microsoft.Crm.Sdk.HowTo

   7:  {

   8:     public class HowToRoute

   9:     {

  10:        static void Main(string[] args)

  11:        {

  12:           // TODO: Change the server URL and organization to match your Microsoft

  13:           // Dynamics CRM Server and Microsoft Dynamics CRM organization.

  14:           HowToRoute.Run("http://localhost:5555", "CRM_SDK");

  15:        }

  16:        

  17:        public static bool Run(string crmServerUrl, string orgName)

  18:        {

  19:           bool success = false;

  20:   

  21:           try

  22:           {

  23:              // Set up the CRM Service.

  24:              CrmService service = CrmServiceUtility.GetCrmService(crmServerUrl, orgName);

  25:   

  26:              // Get the ID of the system user.

  27:              WhoAmIRequest userRequest = new WhoAmIRequest();

  28:              WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest);

  29:   

  30:              #region Setup Data Required for this Sample

  31:              // Create a new customer account.

  32:              account myAccount = new account();

  33:              myAccount.name = "A Bike Store";

  34:              Guid accountID = service.Create(myAccount);

  35:   

  36:              // Create a new subject.

  37:              subject mySubject = new subject();

  38:              mySubject.title = "Bicycles";

  39:              Guid subjectID = service.Create(mySubject);

  40:   

  41:              // Create a new incident.

  42:              incident incident = new incident();

  43:   

  44:              Customer myCustomer = new Customer();

  45:              myCustomer.Value = accountID;

  46:              myCustomer.type = EntityName.account.ToString();

  47:              incident.customerid = myCustomer;

  48:   

  49:              Lookup subjectLookup = new Lookup();

  50:              subjectLookup.Value = subjectID;

  51:              subjectLookup.type = EntityName.subject.ToString();

  52:              incident.subjectid = subjectLookup;

  53:   

  54:              incident.title = "Broken Chain";

  55:              Guid incidentID = service.Create(incident);

  56:   

  57:              // Create a new public Bicycle Cases queue.

  58:              queue publicQueue = new queue();

  59:   

  60:              Lookup businessLookup = new Lookup();

  61:              businessLookup.Value = user.BusinessUnitId;

  62:              businessLookup.type = EntityName.businessunit.ToString();

  63:              publicQueue.businessunitid = businessLookup;

  64:   

  65:              Lookup userLookup = new Lookup();

  66:              userLookup.Value = user.UserId;

  67:              userLookup.type = EntityName.systemuser.ToString();

  68:              publicQueue.primaryuserid = userLookup;

  69:   

  70:              Picklist plist = new Picklist();

  71:              plist.name = "Public";

  72:              plist.Value = 1;

  73:              publicQueue.queuetypecode = plist;

  74:   

  75:              publicQueue.name = "Bicycle Cases";

  76:              Guid publicQueueID = service.Create(publicQueue);

  77:              #endregion

  78:   

  79:              // Find the WIP queue for the user who currently owns the incident.

  80:              // The queue type code for a WIP queue is 3.

  81:              QueryByAttribute query = new QueryByAttribute();

  82:              // Be aware that using AllColumns may adversely affect

  83:              // performance and cause unwanted cascading in subsequent 

  84:              // updates. A best practice is to retrieve the least amount of 

  85:              // data required.

  86:              query.ColumnSet = new AllColumns();

  87:              query.EntityName = EntityName.queue.ToString();

  88:              query.Attributes = new string[] { "primaryuserid", "queuetypecode" };

  89:              query.Values = new string[] { user.UserId.ToString(), "3" };

  90:              BusinessEntityCollection results = service.RetrieveMultiple(query);

  91:   

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

  93:   

  94:              // Create a Target object that refers to the incident.

  95:              TargetQueuedIncident target = new TargetQueuedIncident();

  96:              // SDK:target.EntityId = new Guid("A0F2D8FE-6468-DA11-B748-000D9DD8CDAC");

  97:              target.EntityId = incidentID;

  98:   

  99:              // Route the incident from the WIP queue to the public queue.

 100:              RouteRequest route = new RouteRequest();

 101:              route.Target = target;

 102:              route.RouteType = RouteType.Queue;

 103:              // SDK:route.EndpointId = new Guid("A0F2D8FE-6468-DA11-C748-000D9DD8CDAC");

 104:              route.EndpointId = publicQueueID;

 105:              // SDK:route.SourceQueueId = new Guid("A0F2D8FE-6468-DA11-D748-000D9DD8CDAC");

 106:              route.SourceQueueId = wipQueue.queueid.Value;

 107:   

 108:              RouteResponse routed = null;

 109:              routed = (RouteResponse)service.Execute(route);

 110:   

 111:              #region check success

 112:   

 113:              if (routed != null) success = true;

 114:   

 115:              #endregion

 116:   

 117:              #region Remove Data Required for this Sample

 118:   

 119:              service.Delete(EntityName.incident.ToString(), incidentID);

 120:              service.Delete(EntityName.queue.ToString(), publicQueueID);

 121:              service.Delete(EntityName.subject.ToString(), subjectID);

 122:              service.Delete(EntityName.account.ToString(), accountID);

 123:   

 124:              #endregion

 125:           }

 126:           catch (System.Web.Services.Protocols.SoapException ex)

 127:           {

 128:              Console.WriteLine(String.Format("{0}. {1}", ex.Message, ex.Detail.InnerText));

 129:           }

 130:   

 131:           return success;

 132:        }

 133:     }

 134:  }