public static void CloseCase(OrganizationServiceContext orgContext, IOrganizationService _orgServ, int statusReason, string logiName, Guid incId, string ticket) { if (orgContext != default(OrganizationServiceContext)) { var incidentResolution = new Entity("incidentresolution"); incidentResolution["subject"] = "Anonymised Incident Resolved"; incidentResolution["incidentid"] = new EntityReference(Incident.EntityLogicalName, incId); incidentResolution["description"] = "Test Case"; incidentResolution["timespent"] = 60; var closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = new OptionSetValue(statusReason) }; try { _orgServ.Execute(closeIncidentRequest); } catch (Exception ex) { string errorMsg = ticket + ex.StackTrace; } } }
public void When_a_request_without_incident_resolution_is_called_exception_is_raised() { var context = new XrmFakedContext(); var incident = new Entity { LogicalName = Crm.Incident.EntityLogicalName, Id = Guid.NewGuid() }; context.Initialize(new[] { incident }); var executor = new CloseIncidentRequestExecutor(); CloseIncidentRequest closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = null, Status = new OptionSetValue(StatusProblemSolved) }; Assert.Throws <FaultException <OrganizationServiceFault> >(() => executor.Execute(closeIncidentRequest, context)); }
public bool ResolveTicket(Guid?ticketGuid) { Entity IncidentResolution = new Entity("incidentresolution"); IncidentResolution.Attributes["subject"] = "Subject Closed"; IncidentResolution.Attributes["incidentid"] = new EntityReference("incident", ticketGuid.Value); // Create the request to close the incident, and set its resolution to the // resolution created above CloseIncidentRequest closeRequest = new CloseIncidentRequest(); closeRequest.IncidentResolution = IncidentResolution; // Set the requested new status for the closed Incident closeRequest.Status = new OptionSetValue(5); // Execute the close request try { CloseIncidentResponse closeResponse = (CloseIncidentResponse)_service.Execute(closeRequest); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Successfuly <c>close (resolve)</c> an incident. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.closeincidentrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="id"><c>Incident</c> Id</param> /// <param name="status"><see cref="IncidentResolvedStatusCode"/> status code</param> /// <param name="customStatusCode">If you're using your custom statuscodes set this, otherwise you can set "0 (zero)" or null</param> /// <param name="subject"><c>Incident Resolution</c> subject</param> /// <param name="description"><c>Incident Resolution</c> description</param> /// <param name="resolveDate"><c>Incident Resolution</c> acual end date</param> /// <returns> /// <see cref="CloseIncidentResponse"/> /// </returns> public CloseIncidentResponse Resolve(Guid id, IncidentResolvedStatusCode status, int customStatusCode = 0, string subject = "Resolved Incident", string description = "", DateTime?resolveDate = null) { ExceptionThrow.IfGuidEmpty(id, "id"); int statusCode = (int)status; if (status == IncidentResolvedStatusCode.CustomStatusCode) { ExceptionThrow.IfNegative(customStatusCode, "customStatusCode"); statusCode = customStatusCode; } Entity incidentResolution = new Entity("incidentresolution"); incidentResolution["incidentid"] = new EntityReference(this.EntityName, id); incidentResolution["subject"] = subject; incidentResolution["description"] = description; if (resolveDate.HasValue && resolveDate.Value != DateTime.MinValue) { incidentResolution["actualend"] = resolveDate.Value; } CloseIncidentRequest request = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue(statusCode) }; return((CloseIncidentResponse)this.OrganizationService.Execute(request)); }
public void TestUpdateResolvedIncidentSucceedsWhenFieldModificationIsAllowed() { var incident = new Incident() { Title = "Old Title", }; incident.Id = orgAdminService.Create(incident); var resolution = new IncidentResolution { Subject = "Case closed", IncidentId = incident.ToEntityReference() }; var closeRequest = new CloseIncidentRequest() { IncidentResolution = resolution, Status = new OptionSetValue((int)Incident_StatusCode.ProblemSolved) }; orgAdminService.Execute(closeRequest); var incidentUpdate = new Incident(incident.Id) { StateCode = IncidentState.Active }; orgAdminService.Update(incidentUpdate); var retrievedIncident = Incident.Retrieve(orgAdminService, incident.Id); Assert.Equal(IncidentState.Active, retrievedIncident.StateCode); }
public bool ResolveCase(Incident incident) { try { //Create Incident Resolution var incidentResolution = new IncidentResolution { Subject = "Case Resolved", IncidentId = new EntityReference(Incident.EntityLogicalName, incident.Id), ActualEnd = DateTime.Now }; //Close Incident var closeIncidenRequst = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = new OptionSetValue(5) }; _service.Execute(closeIncidenRequst); _log.Info($"Successfully resolved case {incident.TicketNumber} with id {incident.Id}"); return(true); } catch (Exception ex) { _log.Error($"Exception caught during resolving case {incident.TicketNumber} with id {incident.Id} - {ex.Message}"); return(false); } }
public void When_a_request_without_status_is_called_exception_is_raised() { var context = new XrmFakedContext(); var incident = new Entity { LogicalName = Crm.Incident.EntityLogicalName, Id = Guid.NewGuid() }; context.Initialize(new[] { incident }); Entity incidentResolution = new Entity { LogicalName = Crm.IncidentResolution.EntityLogicalName, ["subject"] = "subject", ["incidentid"] = new EntityReference(Crm.Incident.EntityLogicalName, incident.Id) }; var executor = new CloseIncidentRequestExecutor(); CloseIncidentRequest closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = null }; Assert.Throws <FaultException <OrganizationServiceFault> >(() => executor.Execute(closeIncidentRequest, context)); }
public void When_a_request_with_invalid_incidentid_is_called_exception_is_raised() { var context = new XrmFakedContext(); context.Initialize(new Entity(Crm.Incident.EntityLogicalName) { Id = Guid.NewGuid() }); var executor = new CloseIncidentRequestExecutor(); Entity incidentResolution = new Entity { LogicalName = Crm.IncidentResolution.EntityLogicalName, ["subject"] = "subject", ["incidentid"] = new EntityReference(Crm.Incident.EntityLogicalName, Guid.NewGuid()) }; CloseIncidentRequest closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = new OptionSetValue(StatusProblemSolved) }; Assert.Throws <FaultException <OrganizationServiceFault> >(() => executor.Execute(closeIncidentRequest, context)); }
public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); if (context.InputParameters.Contains("caseRecordId")) { tracing.Trace("contains CaseRecord ID" + ((EntityReference)context.InputParameters["caseRecordId"]).Id); tracing.Trace("contains CaseRecord Name" + ((EntityReference)context.InputParameters["caseRecordId"]).Name); EntityReference Incident = context.InputParameters["Target"] as EntityReference; Entity Incidentresolution = new Entity("incidentresolution"); Incidentresolution["subject"] = "Closed via backend"; Incidentresolution["incidentid"] = Incident; var closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = Incidentresolution, Status = new OptionSetValue(5) }; var closeResponse = (CloseIncidentResponse)service.Execute(closeIncidentRequest); } else { tracing.Trace("Doesnot contain caseRecordId"); } }
public CloseIncidentResponse CloseIncident(EntityReference entityReference, string resolutionSubject, string resolutionDescription) { var portal = PortalCrmConfigurationManager.CreatePortalContext(); var context = portal.ServiceContext; var entity = context.CreateQuery("incident").FirstOrDefault(i => i.GetAttributeValue <Guid>("incidentid") == entityReference.Id); var resolution = new Entity("incidentresolution"); resolution.Attributes["subject"] = resolutionSubject; resolution.Attributes["description"] = resolutionDescription; resolution.Attributes["incidentid"] = entityReference; // Create the request to close the incident, and set its resolution to the // resolution created above var closeRequest = new CloseIncidentRequest { IncidentResolution = resolution, Status = new OptionSetValue((int)IncidentStatusCode.ProblemSolved) }; // Execute the close request var closeResponse = (CloseIncidentResponse)context.Execute(closeRequest); context.TryRemoveFromCache(entity); context.TryRemoveFromCache(resolution); return(closeResponse); }
public void TestCloseIncidentRequestFailsWhenLogicalNameMissing() { var incident = new Incident(); incident.Id = orgAdminUIService.Create(incident); #if (XRM_MOCKUP_TEST_2011 || XRM_MOCKUP_TEST_2013) incident.SetState(orgAdminService, IncidentState.Active, Incident_StatusCode.InProgress); #else incident.StateCode = IncidentState.Active; incident.StatusCode = Incident_StatusCode.InProgress; orgAdminUIService.Update(incident); #endif var incidentResolution = new Entity(); incidentResolution.Attributes["incidentid"] = incident.ToEntityReference(); var request = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue((int)Incident_StatusCode.ProblemSolved) }; try { orgAdminUIService.Execute(request); Assert.Fail(); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(FaultException)); } }
public void TestCloseIncidentRequestFailsWhenIncidentDoesNotExist() { var incident = new Incident(); var incidentResolution = new IncidentResolution { IncidentId = incident.ToEntityReference(), Subject = "Resolved Incident" }; var request = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue((int)Incident_StatusCode.InformationProvided) }; try { orgAdminUIService.Execute(request); throw new XunitException(); } catch (Exception e) { Assert.IsType <FaultException>(e); } }
public void TestCloseIncidentRequestSuccess() { var incident = new Incident(); incident.Id = orgAdminUIService.Create(incident); #if (XRM_MOCKUP_TEST_2011 || XRM_MOCKUP_TEST_2013) incident.SetState(orgAdminService, IncidentState.Active, Incident_StatusCode.InProgress); #else incident.StateCode = IncidentState.Active; incident.StatusCode = Incident_StatusCode.InProgress; orgAdminUIService.Update(incident); #endif var incidentResolution = new IncidentResolution { IncidentId = incident.ToEntityReference(), Subject = "Resolved Incident" }; var request = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue((int)Incident_StatusCode.ProblemSolved) }; var response = orgAdminUIService.Execute(request) as CloseIncidentResponse; Assert.IsNotNull(response); }
public void TestCloseIncidentRequestFailsWhenStatusMissing() { var incident = new Incident(); incident.Id = orgAdminUIService.Create(incident); #if (XRM_MOCKUP_TEST_2011 || XRM_MOCKUP_TEST_2013) incident.SetState(orgAdminService, IncidentState.Active, Incident_StatusCode.InProgress); #else incident.StateCode = IncidentState.Active; incident.StatusCode = Incident_StatusCode.InProgress; orgAdminUIService.Update(incident); #endif var incidentResolution = new IncidentResolution { IncidentId = incident.ToEntityReference(), Subject = "Resolved Incident" }; var request = new CloseIncidentRequest() { IncidentResolution = incidentResolution, }; try { orgAdminUIService.Execute(request); Assert.Fail(); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(FaultException)); } }
public void TestCloseIncidentRequestFailsWhenIncidentidMissing() { var incident = new Incident(); incident.Id = orgAdminUIService.Create(incident); #if (XRM_MOCKUP_TEST_2011 || XRM_MOCKUP_TEST_2013) incident.SetState(orgAdminService, IncidentState.Active, Incident_StatusCode.InProgress); #else incident.StateCode = IncidentState.Active; incident.StatusCode = Incident_StatusCode.InProgress; orgAdminUIService.Update(incident); #endif var incidentResolution = new IncidentResolution { Subject = "Resolved Incident" }; var request = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue((int)Incident_StatusCode.ProblemSolved) }; try { orgAdminUIService.Execute(request); throw new XunitException(); } catch (Exception e) { Assert.IsType <FaultException>(e); } }
private void ResolveCase(IExtendedExecutionContext context, Incident latestCase) { // Change the case built-in status and status reason to Resolved and Problem solved respectively on the latest case created. // Change the Change Email Status to Approved on the latest case created. latestCase[ChangeEmailStatus] = new OptionSetValue(100000004); //Approved latestCase[SubStatusReason] = new OptionSetValue(100000002); //Approved - Confirmed context.OrganizationService.Update(latestCase); // Create Incident Resolution var incidentResolutionResolved = new IncidentResolution { Subject = "Case Resolved", IncidentId = new EntityReference(Incident.EntityLogicalName, latestCase.Id), ActualEnd = DateTime.Now }; // Close Incident var closeIncidentRequestResolved = new CloseIncidentRequest { IncidentResolution = incidentResolutionResolved, Status = new OptionSetValue(5) }; context.OrganizationService.Execute(closeIncidentRequestResolved); context.Trace($"Set case status to Approved for Case with ID {latestCase.Id}"); }
public bool ResolveCase(string incidentId) { log.Info($"{nameof(ResolveCase)} started. Case to resolve Id is {incidentId}"); try { var incidentResolution = new IncidentResolution { Subject = "Resolve Request Incident", IncidentId = new EntityReference(Incident.EntityLogicalName, Guid.Parse(incidentId)) }; var closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = incidentResolution, RequestName = "Resolve Case", Status = new OptionSetValue(5) //resolve case }; var response = crmConnection.Service.Execute(closeIncidentRequest); log.Info("Incident Closed"); return(true); } catch (Exception ex) { log.Error($"{nameof(ResolveCase)} throws exception: {ex.Message}"); Console.WriteLine(ex.Message); return(false); } }
private void CloseIncident(EntityReference caseReference) { // First close the Incident // Create resolution for the closing incident IncidentResolution resolution = new IncidentResolution { Subject = "Case Closed", }; resolution.IncidentId = caseReference; // Create the request to close the incident, and set its resolution to the // resolution created above CloseIncidentRequest closeRequest = new CloseIncidentRequest(); closeRequest.IncidentResolution = resolution; // Set the requested new status for the closed Incident closeRequest.Status = new OptionSetValue((int)incident_statuscode.ProblemSolved); // Execute the close request CloseIncidentResponse closeResponse = (CloseIncidentResponse)_serviceProxy.Execute(closeRequest); //Check if the incident was successfully closed Incident incident = _serviceProxy.Retrieve(Incident.EntityLogicalName, _caseIncidentId, new ColumnSet(allColumns: true)).ToEntity <Incident>(); if (incident.StateCode.HasValue & amp; & incident.StateCode == IncidentState.Resolved) { Console.WriteLine("The incident was closed out as Resolved."); }
public void TestCloseIncidentRequestFailsWhenPreviouslyResolved() { var incident = new Incident(); incident.Id = orgAdminUIService.Create(incident); #if (XRM_MOCKUP_TEST_2011 || XRM_MOCKUP_TEST_2013) incident.SetState(orgAdminService, IncidentState.Active, Incident_StatusCode.InProgress); #else incident.StateCode = IncidentState.Active; incident.StatusCode = Incident_StatusCode.InProgress; orgAdminUIService.Update(incident); #endif var incidentResolution = new IncidentResolution { IncidentId = incident.ToEntityReference(), Subject = "Resolved Incident" }; var request = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue((int)Incident_StatusCode.ProblemSolved) }; var response = orgAdminUIService.Execute(request) as CloseIncidentResponse; Assert.NotNull(response); using (var context = new Xrm(orgAdminUIService)) { var retrievedIncident = context.IncidentSet.FirstOrDefault(x => x.Id == incident.Id); Assert.Equal(IncidentState.Resolved, retrievedIncident.StateCode); Assert.Equal(Incident_StatusCode.ProblemSolved, retrievedIncident.StatusCode); var retrievedIncidentResolution = context.IncidentResolutionSet.FirstOrDefault(x => x.IncidentId.Id == incident.Id); Assert.NotNull(retrievedIncidentResolution); } var incidentResolution2 = new IncidentResolution { IncidentId = incident.ToEntityReference(), Subject = "Resolved Incident" }; var request2 = new CloseIncidentRequest() { IncidentResolution = incidentResolution2, Status = new OptionSetValue((int)Incident_StatusCode.ProblemSolved) }; try { orgAdminUIService.Execute(request2); throw new XunitException(); } catch (Exception e) { Assert.IsType <FaultException>(e); } }
protected override void Execute(CodeActivityContext executionContext) { #region "Load CRM Service from context" Common objCommon = new Common(executionContext); objCommon.tracingService.Trace("Load CRM Service from context --- OK"); #endregion #region "Read Parameters" EntityReference incident = this.Incident.Get(executionContext); string subject = this.IncidentResolution.Get <string>(executionContext); string description = this.ResolutionDescription.Get <string>(executionContext); objCommon.tracingService.Trace(String.Format("IncidentID: {0} - Description: {1} - Subject: {2}", incident.Id.ToString(), description, subject)); #endregion Entity incidentResolution = new Entity("incidentresolution"); incidentResolution.Attributes.Add("incidentid", new EntityReference("incident", incident.Id)); incidentResolution.Attributes.Add("subject", subject); incidentResolution.Attributes.Add("description", description); CloseIncidentRequest closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = new OptionSetValue(5) }; objCommon.service.Execute(closeIncidentRequest); }
/// <summary> /// Closes a Trouble ticket by ID /// </summary> /// <param name="ticketId">ID of the Ticket to close</param> /// <param name="subject">Title of the close ticket record</param> /// <param name="description">Description of the closed ticket</param> /// <param name="batchId">Optional: if set to a valid GUID, generated by the Create Batch Request Method, will assigned the request to the batch for later execution, on fail, runs the request immediately </param> /// <param name="cdsServiceClient">Connected CDS Service Client</param> /// <param name="bypassPluginExecution">Adds the bypass plugin behavior to this request. Note: this will only apply if the caller has the prvBypassPlugins permission to bypass plugins. If its attempted without the permission the request will fault.</param> /// <returns>Returns the ID of the closed ticket</returns> public static Guid CloseTroubleTicket(this CdsServiceClient cdsServiceClient, Guid ticketId, string subject, string description, Guid batchId = default(Guid), bool bypassPluginExecution = false) { // ONE OF THEASE SOULD BE MADE THE MASTER cdsServiceClient.logEntry.ResetLastError(); // Reset Last Error if (cdsServiceClient._CdsService == null) { cdsServiceClient.logEntry.Log("Crm Service not initialized", TraceEventType.Error); return(Guid.Empty); } if (ticketId == Guid.Empty) { return(Guid.Empty); } // Create Incident Resolution Type Entity reso = new Entity("incidentresolution"); Guid closeTicketId = Guid.NewGuid(); reso.Attributes.Add("activityid", closeTicketId); reso.Attributes.Add("incidentid", new EntityReference("incident", ticketId)); // NEED TO REWORK THIS WITH METAD DATA> reso.Attributes.Add("statecode", new OptionSetValue(1)); reso.Attributes.Add("statuscode", new OptionSetValue(2)); reso.Attributes.Add("subject", subject); reso.Attributes.Add("description", description); // Set Close Time Stamp reso.Attributes.Add("actualend", DateTime.Now.ToString()); // Get State close for Resolving a case int defaultStateCodeForResolveCase = 1; CloseIncidentRequest req4 = new CloseIncidentRequest(); req4.IncidentResolution = reso; req4.Status = new OptionSetValue(defaultStateCodeForResolveCase); if (cdsServiceClient.AddRequestToBatch(batchId, req4, "Calling Close Incident", "Request to Close Incident Queued", bypassPluginExecution)) { return(Guid.Empty); } CloseIncidentResponse resp4 = (CloseIncidentResponse)cdsServiceClient.CdsCommand_Execute(req4, "Closing a Case in CRM", bypassPluginExecution); if (resp4 != null) { return(closeTicketId); } else { return(Guid.Empty); } }
public void ResolveCase(Guid caseId) { try { using (var context = new XrmServiceContext(_service)) { _log.Info($"Executing resolve case for case with id {caseId}"); Incident selectedCase = (from incident in context.IncidentSet where incident.IncidentId.Equals(caseId) select incident) .FirstOrDefault(); if (selectedCase == null) { _log.Info($"No case found with id {caseId}"); return; } var statuses = (from status in context.New_requeststatusSet select status) .ToList(); //Set case status to "Completed" selectedCase.new_caseid.Id = statuses[0].Id; //Create Incident Resolution var incidentResolution = new IncidentResolution { Subject = "Case Resolved", IncidentId = new EntityReference(Incident.EntityLogicalName, selectedCase.Id), ActualEnd = DateTime.Now }; //Close Incident var closeIncidenRequst = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = new OptionSetValue(5) }; _service.Execute(closeIncidenRequst); context.UpdateObject(selectedCase); context.SaveChanges(); _log.Info($"Set case status to Completed for Case with ID {caseId}"); } } catch (Exception ex) { _log.Error($"Exception caught while trying to resolve case with ID {caseId} - {ex.Message}"); } }
private CloseIncidentResponse ExecuteInternal(CloseIncidentRequest request) { Create(request.IncidentResolution); Update(new Entity { Id = request.IncidentResolution.GetAttributeValue <EntityReference>(Incident.Fields.IncidentId).GetIdOrDefault(), LogicalName = Incident.EntityLogicalName, [Incident.Fields.StatusCode] = request.Status, [Incident.Fields.StateCode] = new OptionSetValue((int)IncidentState.Resolved) }); return(new CloseIncidentResponse()); }
//Under Dev public bool ResolveIncident(string ticketId) { var service = this.db.Connect(); try { using (ServiceContext context = new ServiceContext(service)) { var caseToResolve = (from incident in context.IncidentSet //join caseStatus in context.New_requeststatusSet on incident.new_caseid.Id equals caseStatus.New_requeststatusId where incident.TicketNumber.Equals(ticketId) select incident ) .FirstOrDefault(); var statusesInCrm = (from status in context.New_requeststatusSet select status) .ToList(); //Change ticket CaseStatus to Completed caseToResolve.new_caseid.Id = statusesInCrm[0].Id; context.UpdateObject(caseToResolve); context.SaveChanges(); var incidentResolution = new IncidentResolution { Subject = "Case Resolved", IncidentId = new EntityReference(Incident.EntityLogicalName, caseToResolve.Id), ActualEnd = DateTime.Now, }; var closeIncidenRequst = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = new OptionSetValue(5) //new OptionSetValue((int)) }; var response = (CloseIncidentResponse)service.Execute(closeIncidenRequst); } } catch (Exception ex) { Console.WriteLine($"Exception throw during changing status of Ticket: {ex.Message}"); return(false); } return(true); }
protected override void ExecuteWorkflowLogic(CodeActivityContext executionContext, IWorkflowContext context, IOrganizationService service) { var incidentCloseRequest = new CloseIncidentRequest() { Status = IncidentStatus.Get(executionContext), IncidentResolution = new Entity("incidentresolution") { ["subject"] = Subject.Get(executionContext), ["incidentid"] = Incident.Get(executionContext), ["actualend"] = CloseDate.Get(executionContext), ["description"] = Description.Get(executionContext) } }; service.Execute(incidentCloseRequest); }
protected override void ExecuteWorkflowLogic() { var incidentCloseRequest = new CloseIncidentRequest() { Status = IncidentStatus.Get(Context.ExecutionContext), IncidentResolution = new Entity("incidentresolution") { ["subject"] = Subject.Get(Context.ExecutionContext), ["incidentid"] = Incident.Get(Context.ExecutionContext), ["description"] = Description.Get(Context.ExecutionContext), ["timespent"] = TimeSpent.Get(Context.ExecutionContext) } }; Context.UserService.Execute(incidentCloseRequest); }
public async Task <IncidentDto> PatchIncident(string id, Delta <IncidentDto> patch) { /*var current = (await this.LookupAsync(id)).Queryable.First(); * this.Services.Log.Info("Current item: " + current.Id + ", '" + current.Text + "', completed: " + current.Complete.ToString()); * patch.Patch(current); * this.Services.Log.Info("Patch simulation: " + current.Id + ", '" + current.Text + "', completed: " + current.Complete.ToString());*/ if (patch.GetChangedPropertyNames().Contains("Complete") == true) { this.Services.Log.Info("resolving the case"); Guid entityId; if (!Guid.TryParse(id, out entityId)) { return(null); } //case resolution requires special handling var incidentResolution = new IncidentResolution() { Subject = "Resolved Incident", IncidentId = new EntityReference(Incident.EntityLogicalName, entityId) }; var closeIncidentRequest = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue(5) }; await this.DynamicsCrmDomainManager.Execute(closeIncidentRequest); return((await this.LookupAsync(id)).Queryable.First()); } else { var item = await this.UpdateAsync(id, patch); this.Services.Log.Info("Updated item: " + item.Id + ", '" + item.Text + "', completed: " + item.Complete.ToString()); /*Incident incident = this.EntityMapper.Map(item); * this.Services.Log.Info("Updated incident: " + incident.Id.ToString() + ", '" + incident.Title + "', completed: " + incident.StatusCode.Value.ToString());*/ return(item); } }
public void PerformTestSetup() { MessageName = "Close"; var caseEntity = EntityFactory.CreateCase(); var caseResolutionEntity = new Entity("incidentresolution") { Id = Guid.NewGuid() }; caseResolutionEntity["incidentid"] = caseEntity.ToEntityReference(); CloseIncidentRequest = new CloseIncidentRequest { IncidentResolution = caseResolutionEntity, Status = new OptionSetValue(5), }; }
public void TestUpdateResolvedIncidentFailsWhenFieldModificationIsNotAllowed() { var incident = new Incident() { Title = "Old Title" }; incident.Id = orgAdminService.Create(incident); var resolution = new IncidentResolution { Subject = "Case closed", IncidentId = incident.ToEntityReference() }; var closeRequest = new CloseIncidentRequest() { IncidentResolution = resolution, Status = new OptionSetValue((int)Incident_StatusCode.ProblemSolved) }; orgAdminService.Execute(closeRequest); var incidentUpdate = new Incident(incident.Id) { Title = "New Title" }; try { orgAdminService.Update(incidentUpdate); throw new XunitException(); } catch (Exception e) { Assert.IsType <FaultException>(e); } var retrievedIncident = Incident.Retrieve(orgAdminService, incident.Id); Assert.Equal(incident.Title, retrievedIncident.Title); }
public async Task <bool> Resolve(int currentIndex, int maxCount, Guid incidentId, bool isPrintingProgress) { bool isOperationSuccessfull = false; var ctx = DcrmConnectorFactory.GetContext(); var dcrmConnector = DcrmConnectorFactory.Get(); var srv = dcrmConnector.GetService(); var incident = new EntityReference(Incident.EntityLogicalName, incidentId); IncidentResolution incidentResolution = new IncidentResolution { IncidentId = incident, StatusCode = new OptionSetValue(5) }; CloseIncidentRequest closeIncidentReq = new CloseIncidentRequest() { IncidentResolution = incidentResolution, Status = new OptionSetValue(5) }; try { ctx.Execute(closeIncidentReq); if (isPrintingProgress) { MiscHelper.DisplayProgression(maxCount); } isOperationSuccessfull = true; } catch (Exception ex) { var message = string.Format($"Could not close the incident : {incidentId} : {ex.Message} "); MiscHelper.PrintMessage(message); } return(isOperationSuccessfull); }
private void RunIncidentManipulation() { Console.WriteLine("=== Creating and Closing an Incident (Case) ==="); // Create an incident. var incident = new Incident { CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), Title = "Sample Incident" }; _incidentId = _serviceProxy.Create(incident); NotifyEntityCreated(Incident.EntityLogicalName, _incidentId); // Create a 30-minute appointment regarding the incident. var appointment = new Appointment { ScheduledStart = DateTime.Now, ScheduledEnd = DateTime.Now.Add(new TimeSpan(0, 30, 0)), Subject = "Sample 30-minute Appointment", RegardingObjectId = new EntityReference(Incident.EntityLogicalName, _incidentId) }; _appointmentId = _serviceProxy.Create(appointment); NotifyEntityCreated(Appointment.EntityLogicalName, _appointmentId); // Show the time spent on the incident before closing the appointment. NotifyTimeSpentOnIncident(); // Check the validity of the state transition to closed on the incident. NotifyValidityOfIncidentSolvedStateChange(); //<snippetCloseAnIncident1> // Close the appointment. var setAppointmentStateReq = new SetStateRequest { EntityMoniker = new EntityReference(Appointment.EntityLogicalName, _appointmentId), State = new OptionSetValue((int)AppointmentState.Completed), Status = new OptionSetValue((int)appointment_statuscode.Completed) }; _serviceProxy.Execute(setAppointmentStateReq); Console.WriteLine(" Appointment state set to completed."); //</snippetCloseAnIncident1> // Show the time spent on the incident after closing the appointment. NotifyTimeSpentOnIncident(); // Check the validity of the state transition to closed again. NotifyValidityOfIncidentSolvedStateChange(); // Create the incident's resolution. var incidentResolution = new IncidentResolution { Subject = "Resolved Sample Incident", IncidentId = new EntityReference(Incident.EntityLogicalName, _incidentId) }; //<snippetCloseAnIncident2> // Close the incident with the resolution. var closeIncidentRequest = new CloseIncidentRequest { IncidentResolution = incidentResolution, Status = new OptionSetValue((int)incident_statuscode.ProblemSolved) }; _serviceProxy.Execute(closeIncidentRequest); Console.WriteLine(" Incident closed."); //</snippetCloseAnIncident2> }
private void CloseIncident(EntityReference caseReference) { //<snippetCloseIncident> // First close the Incident // Create resolution for the closing incident IncidentResolution resolution = new IncidentResolution { Subject = "Case Closed", }; resolution.IncidentId = caseReference; // Create the request to close the incident, and set its resolution to the // resolution created above CloseIncidentRequest closeRequest = new CloseIncidentRequest(); closeRequest.IncidentResolution = resolution; // Set the requested new status for the closed Incident closeRequest.Status = new OptionSetValue((int)incident_statuscode.ProblemSolved); // Execute the close request CloseIncidentResponse closeResponse = (CloseIncidentResponse)_serviceProxy.Execute(closeRequest); //Check if the incident was successfully closed Incident incident = _serviceProxy.Retrieve(Incident.EntityLogicalName, _caseIncidentId, new ColumnSet(allColumns: true)).ToEntity<Incident>(); if (incident.StateCode.HasValue && incident.StateCode == IncidentState.Resolved) { Console.WriteLine("The incident was closed out as Resolved."); } else { Console.WriteLine("The incident's state was not changed."); } //</snippetCloseIncident> }