private void UpdateReferenceSR(IOrganizationService service, Guid referenceSR, Guid reclassifiedSR, ITracingService trace)
 {
     try
     {
         if (service != null)
         {
             //// Update Request Cancelled Reason
             Entity serviceRequest = new Entity();
             serviceRequest.LogicalName           = "incident";
             serviceRequest.Id                    = referenceSR;
             serviceRequest["smp_reclassifiedsr"] = new EntityReference("incident", reclassifiedSR);
             trace.Trace("reclassified SR : " + reclassifiedSR);
             serviceRequest["smp_requestcancelledreason"]       = "Reclassification";
             serviceRequest["smp_cancelledforreclassification"] = true;
             trace.Trace("after updateding smp_cancelledforreclassification =  true ");
             service.Update(serviceRequest);
             trace.Trace("after update sr call");
             //// Cancel Service Request
             Microsoft.Crm.Sdk.Messages.SetStateRequest state = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
             //// Set the Request Object's Properties to cancelled
             state.State  = new OptionSetValue(2); //// cancelled
             state.Status = new OptionSetValue(6); //// cancelled
             //// case whose state is being changed
             state.EntityMoniker = new EntityReference("incident", referenceSR);
             //// Execute the Request
             service.Execute(state);
             ////this.IntegartionForCancelledServiceRequest(service, referenceSR,trace);
         }
     }
     catch (Exception)
     {
     }
 }
        public static void UpdateStepStatus(CrmOrganization org, Guid stepId, bool isEnable)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (stepId == Guid.Empty)
            {
                throw new ArgumentException("Invalid Guid", "stepId");
            }

            Microsoft.Crm.Sdk.Messages.SetStateRequest request = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
            request.EntityMoniker = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, stepId);
            if (isEnable)
            {
                request.State = new OptionSetValue((int)SdkMessageProcessingStepState.Enabled);
            }
            else
            {
                request.State = new OptionSetValue((int)SdkMessageProcessingStepState.Disabled);
            }
            request.Status = new OptionSetValue(-1);
            org.OrganizationService.Execute(request);

            return;
        }
Beispiel #3
0
        public Guid?CreateTaskToCRMIncident(string ticketnumber, TimeItem timeItem)
        {
            try
            {
                Microsoft.Xrm.Sdk.Query.QueryExpression GetCasesByTicketNumber = new Microsoft.Xrm.Sdk.Query.QueryExpression {
                    EntityName = "incident", ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true)
                };
                GetCasesByTicketNumber.Criteria.AddCondition("ticketnumber", Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal, ticketnumber);
                Microsoft.Xrm.Sdk.EntityCollection CaseResults = _service.RetrieveMultiple(GetCasesByTicketNumber);

                if (CaseResults.Entities.Count < 1)
                {
                    return(null);
                }

                Microsoft.Xrm.Sdk.Entity followup = new Microsoft.Xrm.Sdk.Entity("task");

                if (timeItem.title != null)
                {
                    followup["subject"] = timeItem.title.Replace(ticketnumber, "");
                }

                if (timeItem.description != null)
                {
                    followup["description"] = timeItem.description;
                }

                if (timeItem.isBillable == true && timeItem.isBillable != null)
                {
                    followup["actualdurationminutes"]    = (int)TimeSpan.Parse(timeItem.time).TotalMinutes;
                    followup["hsal_nonbillableduration"] = 0;
                }
                else
                {
                    followup["actualdurationminutes"]    = 0;
                    followup["hsal_nonbillableduration"] = (int)TimeSpan.Parse(timeItem.time).TotalMinutes;
                }

                followup["actualstart"] = DateTime.UtcNow;

                followup["regardingobjectid"] = CaseResults.Entities[0].ToEntityReference();

                Guid taskId = _service.Create(followup);

                Microsoft.Crm.Sdk.Messages.SetStateRequest req = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
                req.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference("task", taskId);
                req.State         = new Microsoft.Xrm.Sdk.OptionSetValue(1);
                req.Status        = new Microsoft.Xrm.Sdk.OptionSetValue((5));
                _service.Execute(req);

                return(taskId);
            }
            catch (Exception ex)
            {
                //log error
                throw ex;
            }
        }
Beispiel #4
0
        public static Microsoft.Crm.Sdk.Messages.SetStateRequest Get_SetStateRequest(string entityName, Guid entityId, int stateVal, int statusVal)
        {
            Microsoft.Crm.Sdk.Messages.SetStateRequest setStateRequest = new Microsoft.Crm.Sdk.Messages.SetStateRequest();

            // Set the Request Object's Properties
            setStateRequest.State  = new Microsoft.Xrm.Sdk.OptionSetValue(stateVal);
            setStateRequest.Status = new Microsoft.Xrm.Sdk.OptionSetValue(statusVal);

            // Point the Request to the case whose state is being changed
            setStateRequest.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference(entityName, entityId);
            return(setStateRequest);
        }
        /// <summary>
        /// Sets the status code on the entity with the given id.
        /// </summary>
        public void SetStatus(Guid id, int statusCode, int stateCode)
        {
            var logicalName = (string)typeof(T).GetField("EntityLogicalName", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null);

            var request = new Microsoft.Crm.Sdk.Messages.SetStateRequest()
            {
                EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference(logicalName, id),
                State         = new Microsoft.Xrm.Sdk.OptionSetValue(stateCode),
                Status        = new Microsoft.Xrm.Sdk.OptionSetValue(statusCode)
            };

            this.context.Execute(request);
        }
Beispiel #6
0
        public bool?UpdateTaskInCRM(string ticketnumber, TimeItem timeItem)
        {
            try
            {
                Microsoft.Xrm.Sdk.Entity followup = _service.Retrieve("task", (Guid)timeItem.crmTaskId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));

                Microsoft.Crm.Sdk.Messages.SetStateRequest req = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
                req.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference("task", followup.Id);
                req.State         = new Microsoft.Xrm.Sdk.OptionSetValue(0);
                req.Status        = new Microsoft.Xrm.Sdk.OptionSetValue((-1));
                _service.Execute(req);

                if (timeItem.title != null)
                {
                    followup["subject"] = timeItem.title.Replace(ticketnumber, "");
                }

                if (timeItem.description != null)
                {
                    followup["description"] = timeItem.description;
                }

                if (timeItem.isBillable == true && timeItem.isBillable != null)
                {
                    followup["actualdurationminutes"]    = (int)TimeSpan.Parse(timeItem.time).TotalMinutes;
                    followup["hsal_nonbillableduration"] = 0;
                }
                else
                {
                    followup["actualdurationminutes"]    = 0;
                    followup["hsal_nonbillableduration"] = (int)TimeSpan.Parse(timeItem.time).TotalMinutes;
                }


                _service.Update(followup);

                req.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference("task", followup.Id);
                req.State         = new Microsoft.Xrm.Sdk.OptionSetValue(1);
                req.Status        = new Microsoft.Xrm.Sdk.OptionSetValue((5));
                _service.Execute(req);

                return(true);
            }
            catch (Exception ex)
            {
                //log error
                throw ex;
            }
        }
Beispiel #7
0
        public Guid?CreateExternalComment(string ticketnumber, TimeItem timeItem)
        {
            try
            {
                Microsoft.Xrm.Sdk.Query.QueryExpression GetCasesByTicketNumber = new Microsoft.Xrm.Sdk.Query.QueryExpression {
                    EntityName = "incident", ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true)
                };
                GetCasesByTicketNumber.Criteria.AddCondition("ticketnumber", Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal, ticketnumber);
                Microsoft.Xrm.Sdk.EntityCollection CaseResults = _service.RetrieveMultiple(GetCasesByTicketNumber);

                if (CaseResults.Entities.Count < 1)
                {
                    return(null);
                }

                Microsoft.Xrm.Sdk.Entity comment = new Microsoft.Xrm.Sdk.Entity("hsal_externalcomments");

                if (timeItem.title != null)
                {
                    comment["subject"] = timeItem.title.Replace(ticketnumber, "");
                }

                if (timeItem.description != null)
                {
                    comment["description"] = timeItem.description;
                }

                comment["regardingobjectid"] = CaseResults.Entities[0].ToEntityReference();

                Guid externalCommentId = _service.Create(comment);

                Microsoft.Crm.Sdk.Messages.SetStateRequest req = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
                req.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference("hsal_externalcomments", externalCommentId);
                req.State         = new Microsoft.Xrm.Sdk.OptionSetValue(1);
                req.Status        = new Microsoft.Xrm.Sdk.OptionSetValue((2));
                _service.Execute(req);

                return(externalCommentId);
            }
            catch (Exception ex)
            {
                //log error
                throw ex;
            }
        }
Beispiel #8
0
        public bool?DeactivateExternalCommentInCRM(TimeItem timeItem)
        {
            try
            {
                Microsoft.Xrm.Sdk.Entity comment = _service.Retrieve("hsal_externalcomments", (Guid)timeItem.crmExternalCommentId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));

                Microsoft.Crm.Sdk.Messages.SetStateRequest req = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
                req.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference("hsal_externalcomments", comment.Id);
                req.State         = new Microsoft.Xrm.Sdk.OptionSetValue(2);
                req.Status        = new Microsoft.Xrm.Sdk.OptionSetValue((-1));
                _service.Execute(req);

                return(true);
            }
            catch (Exception ex)
            {
                //log error
                throw ex;
            }
        }
Beispiel #9
0
        public bool?UpdateExternalCommentInCRM(string ticketnumber, TimeItem timeItem)
        {
            try
            {
                Microsoft.Xrm.Sdk.Entity comment = _service.Retrieve("hsal_externalcomments", (Guid)timeItem.crmExternalCommentId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));

                Microsoft.Crm.Sdk.Messages.SetStateRequest req = new Microsoft.Crm.Sdk.Messages.SetStateRequest();
                req.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference("hsal_externalcomments", comment.Id);
                req.State         = new Microsoft.Xrm.Sdk.OptionSetValue(0);
                req.Status        = new Microsoft.Xrm.Sdk.OptionSetValue((-1));
                _service.Execute(req);

                if (timeItem.title != null)
                {
                    comment["subject"] = timeItem.title.Replace(ticketnumber, "");
                }

                if (timeItem.description != null)
                {
                    comment["description"] = timeItem.description;
                }

                _service.Update(comment);

                req.EntityMoniker = new Microsoft.Xrm.Sdk.EntityReference("hsal_externalcomments", comment.Id);
                req.State         = new Microsoft.Xrm.Sdk.OptionSetValue(1);
                req.Status        = new Microsoft.Xrm.Sdk.OptionSetValue((2));
                _service.Execute(req);

                return(true);
            }
            catch (Exception ex)
            {
                //log error
                throw ex;
            }
        }