/// <summary> /// Add the specified <c>Principal</c> to the list of <c>Queue</c> members. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addprincipaltoqueuerequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="queueId"><c>Queue</c> Id</param> /// <param name="principalType"><c>System User</c> or <c>Team</c>. If the passed-in <c>PrincipalType.Team</c> , add each team member to the queue.</param> /// <param name="principalId"><c>Principal</c> Id</param> /// <returns> /// <see cref="AddPrincipalToQueueResponse"/> /// </returns> public AddPrincipalToQueueResponse AddPrincipalToQueue(Guid queueId, PrincipalType principalType, Guid principalId) { ExceptionThrow.IfGuidEmpty(queueId, "queueId"); ExceptionThrow.IfGuidEmpty(principalId, "principalId"); Entity principalEntity = null; switch (principalType) { case PrincipalType.SystemUser: SystemUserHelper systemuserHelper = new SystemUserHelper(this.OrganizationService); principalEntity = systemuserHelper.Get(principalId, "fullname"); break; case PrincipalType.Team: TeamHelper teamHelper = new TeamHelper(this.OrganizationService); principalEntity = teamHelper.Get(principalId, "name"); break; } ExceptionThrow.IfNull(principalEntity, "principal", string.Format("Principal not found with '{0}'", principalId.ToString())); AddPrincipalToQueueRequest request = new AddPrincipalToQueueRequest() { QueueId = queueId, Principal = principalEntity }; return((AddPrincipalToQueueResponse)this.OrganizationService.Execute(request)); }
private void AddUserToQueue(Entity user, Guid queueId) { var addPrincipalToQueueRequest = new AddPrincipalToQueueRequest { Principal = user, QueueId = queueId }; _client.Execute(addPrincipalToQueueRequest); }
/// <summary> /// Create and configure the organization service proxy. /// Initiate the method to create any data that this sample requires. /// Share a queue to the team. /// Optionally delete any entity records that were created for this sample. /// <param name="serverConfig">Contains server connection information.</param> /// <param name="promptforDelete">When True, the user will be prompted to delete all /// created entities.</param> /// </summary> public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete) { try { // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); CreateRequiredRecords(); ////<snippetAddPrincipalToQueue1> ColumnSet columnSet = new ColumnSet("name"); Entity team = _serviceProxy.Retrieve(Team.EntityLogicalName, _teamId, columnSet); AddPrincipalToQueueRequest addPrincipalToQueueRequest = new AddPrincipalToQueueRequest { Principal = team, QueueId = _queueId }; _serviceProxy.Execute(addPrincipalToQueueRequest); //</snippetAddPrincipalToQueue1> Console.WriteLine("The team has been added to the queue."); DeleteRequiredRecords(promptForDelete); } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { // You can handle an exception here or pass it back to the calling method. throw; } }
[STAThread] // Added to support UX static void Main(string[] args) { CrmServiceClient service = null; try { service = SampleHelpers.Connect("Connect"); if (service.IsReady) { #region Sample Code ////////////////////////////////////////////// #region Set up SetUpSample(service); #endregion Set up #region Demonstrate ColumnSet columnSet = new ColumnSet("name"); Entity team = service.Retrieve(Team.EntityLogicalName, _teamId, columnSet); var addPrincipalToQueueRequest = new AddPrincipalToQueueRequest { Principal = team, QueueId = _queueId }; service.Execute(addPrincipalToQueueRequest); Console.WriteLine("The team has been added to the queue."); #region Clean up CleanUpSample(service); #endregion Clean up } #endregion Demonstrate else { const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Common Data Service"; if (service.LastCrmError.Equals(UNABLE_TO_LOGIN_ERROR)) { Console.WriteLine("Check the connection string values in cds/App.config."); throw new Exception(service.LastCrmError); } else { throw service.LastCrmException; } } } #endregion Sample Code catch (Exception ex) { SampleHelpers.HandleException(ex); } finally { if (service != null) { service.Dispose(); } Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
/// <summary> /// Create and configure the organization service proxy. /// Initiate the method to create any data that this sample requires. /// Share a queue to the team. /// Optionally delete any entity records that were created for this sample. /// <param name="serverConfig">Contains server connection information.</param> /// <param name="promptforDelete">When True, the user will be prompted to delete all /// created entities.</param> /// </summary> public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete) { try { // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); CreateRequiredRecords(); ////<snippetAddPrincipalToQueue1> ColumnSet columnSet = new ColumnSet("name"); Entity team = _serviceProxy.Retrieve(Team.EntityLogicalName, _teamId, columnSet); AddPrincipalToQueueRequest addPrincipalToQueueRequest = new AddPrincipalToQueueRequest { Principal = team, QueueId = _queueId }; _serviceProxy.Execute(addPrincipalToQueueRequest); //</snippetAddPrincipalToQueue1> Console.WriteLine("The team has been added to the queue."); DeleteRequiredRecords(promptForDelete); } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>) { // You can handle an exception here or pass it back to the calling method. throw; } }