public void PublishInCRM(ServiceRequest serviceRequest) { //Connects to the database and Logs the User In var connection = ConnectToDatabase(); var service = new OrganizationService(connection); var context = new CrmOrganizationServiceContext(connection); //const int hour = 60; EventLog.saveMessage("PublishIssue SRID:" + serviceRequest.SRID); //Creating the new Case Entity incident = new Entity("incident"); try { //Filling the Data for the new case incident["createdon"] = serviceRequest.RegistrationDate; incident["description"] = serviceRequest.LongDescription; incident["statuscode"] = ReturnStatusCode(serviceRequest.ServiceRequestStatus); incident["subjectid"] = ReturnRequestType(serviceRequest.ServiceRequestType); incident["new_moduleoptionset"] = ReturnModuleCode("TS"); //incident["ownerid"] = new EntityReference("systemuser", findConsultantID(serviceRequest.AssignedPerson, service)); incident["new_caseasignedto"] = serviceRequest.AssignedPerson; incident["new_statushistory"] = serviceRequest.CommentsMatricia; incident["casetypecode"] = returnRequestKind(serviceRequest.ServiceRequestKind); incident["followupby"] = serviceRequest.DueDate; incident["new_supportrequestid"] = serviceRequest.SRID; incident["title"] = serviceRequest.AssignedToClient + " " + serviceRequest.SRID + " " + serviceRequest.companyName; //incident["customerid"] = new EntityReference("account", findCustomer((string)serviceRequest.companyName, service)); incident["customerid"] = new EntityReference("account", findCustomerID(serviceRequest.companyName)); incident["new_statushistory"] = serviceRequest.ShortDescription; incident["new_assignedfrom"] = serviceRequest.CreatedBy; Guid consultantID = findConsultantID(serviceRequest.AssignedPerson, service); //Adding the created case to CRM; var incidentGuid = service.Create(incident); //Assign a case! EventLog.saveMessage("Start of Assignment! to :" + consultantID); AssignRequest assignRequest = new AssignRequest(); assignRequest.Assignee = new EntityReference("systemuser", consultantID); assignRequest.Target = new EntityReference(incident.LogicalName, incidentGuid); service.Execute(assignRequest); } catch (Exception) { EventLog.saveMessage("This case was not created in CRM " + serviceRequest.CreatedBy + "'" + serviceRequest.SRID); ; } }
public void UpdateStatus(ServiceRequest serviceRequest) { var idOfUpdatedItem = serviceRequest.SRID; //Login and connect to the server and create the context var connection = ConnectToDatabase(); var service = new OrganizationService(connection); var context = new CrmOrganizationServiceContext(connection); //Gather the components for the "Retrieve" function ColumnSet set = new ColumnSet(); set.AllColumns = true; Guid incidentGuid = GetGUIDByName(idOfUpdatedItem, service); //Retrieves the record that will be updated var incident = service.Retrieve("incident", incidentGuid, set); EventLog.saveMessage("Update Status of SRID:" + serviceRequest.SRID); try { // Actual UPDATE of the record. incident["description"] = serviceRequest.LongDescription; incident["statuscode"] = ReturnStatusCode(serviceRequest.ServiceRequestStatus); incident["subjectid"] = ReturnRequestType(serviceRequest.ServiceRequestType); incident["new_moduleoptionset"] = ReturnModuleCode("TS"); //incident["ownerid"] = new EntityReference("systemuser", findConsultantID(serviceRequest.AssignedPerson,service)); incident["new_statushistory"] = serviceRequest.CommentsMatricia; incident["casetypecode"] = returnRequestKind(serviceRequest.ServiceRequestKind); incident["new_caseasignedto"] = serviceRequest.AssignedPerson; //incident["followupby"] = serviceRequest.DueDate; incident["title"] = serviceRequest.AssignedToClient + " " + serviceRequest.SRID + " " + serviceRequest.companyName; //incident["customerid"] = new EntityReference("account", findCustomer((string)serviceRequest.companyName, service)); incident["customerid"] = new EntityReference("account", findCustomerID(serviceRequest.companyName)); incident["new_statushistory"] = serviceRequest.ShortDescription; incident["new_assignedfrom"] = serviceRequest.CreatedBy; Guid consultantID = findConsultantID(serviceRequest.AssignedPerson, service); //Assign a case! service.Update(incident); EventLog.saveMessage("Start of Assignment! to :" + consultantID); AssignRequest assignRequest = new AssignRequest(); assignRequest.Assignee = new EntityReference("systemuser", consultantID); assignRequest.Target = new EntityReference(incident.LogicalName, incidentGuid); service.Execute(assignRequest); } catch (Exception) { EventLog.saveMessage("This record is unavailable for update right now!" + serviceRequest.SRID); return; } }
public void UpdateAssignedPerson(ServiceRequest serviceRequest) { var idOfUpdatedItem = serviceRequest.SRID; var connection = ConnectToDatabase(); var service = new OrganizationService(connection); var context = new CrmOrganizationServiceContext(connection); Guid consultantID = findConsultantID(serviceRequest.AssignedPerson, service); ColumnSet set = new ColumnSet(); set.AllColumns = true; //Gather the components for the "Retrieve" function Guid incidentGuid = GetGUIDByName(idOfUpdatedItem, service); //Retrieves the record that will be updated var incident = service.Retrieve("incident", incidentGuid, set); EventLog.saveMessage("Updating the consultant person of case: " + serviceRequest.SRID + "to " + serviceRequest.AssignedPerson); try { //Assign a case! AssignRequest assignRequest = new AssignRequest(); assignRequest.Assignee = new EntityReference("systemuser", consultantID); assignRequest.Target = new EntityReference(incident.LogicalName, incidentGuid); //sets the new User. //incident["ownerid"] = new EntityReference("systemuser", consultantID); service.Update(incident); service.Execute(assignRequest); } catch (Exception) { EventLog.saveMessage("Updating the consultant person of case: " + serviceRequest.SRID + "to " + serviceRequest.AssignedPerson + " failed!"); return; } }