public CRMTask CRMCreateTask(CRMTask crmTask)
        {
            OrganizationServiceProxy _serviceProxy;
            IOrganizationService _service;
            string res = "";
            List<CRMState> returnEntities = new List<CRMState>();

            using (_serviceProxy = GetCRMConnection())
            {
                // This statement is required to enable early-bound type support.
                _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

                _service = (IOrganizationService)_serviceProxy;

                try
                {
                    Entity task = new Entity();
                    task.LogicalName = "task";
                    task["subject"] = crmTask.Subject;
                    task["description"] = crmTask.Description;
                    task["category"] = crmTask.Category;
                    task["subcategory"] = crmTask.Subcategory;
                    if (!string.IsNullOrEmpty(crmTask.RegardingId.Trim()) && !string.IsNullOrEmpty(crmTask.Regarding.Trim()))
                    {
                        task["regardingobjectid"] = new EntityReference(crmTask.Regarding.ToLower(), new Guid(crmTask.RegardingId));
                    }

                    // assumes that the K2 CRM solution has been deployed
                    task["k2_k2serialnumber"] = crmTask.K2SerialNumber;
                    task["k2_k2activityname"] = crmTask.K2ActivityName;
                    task["k2_k2processname"] = crmTask.K2ProcessName;
                    task["k2_k2processinstanceid"] = crmTask.K2ProcessInstanceId;
                    
                    task["scheduleddurationminutes"] = crmTask.Duration;
                    task["scheduledend"] = crmTask.DueDate;
                    task["prioritycode"] = new OptionSetValue(crmTask.Priority);
                    task["statecode"] = new OptionSetValue(crmTask.State);
                    task["statuscode"] = new OptionSetValue(crmTask.Status);

                    Guid newtask = _service.Create(task);

                    crmTask.Id = newtask.ToString();

                    if (string.IsNullOrEmpty(crmTask.OwnerId.Trim()) && !string.IsNullOrEmpty(crmTask.OwnerFQN.Trim()))
                    {
                        CRMUser cu = new CRMUser();
                        cu.UserFQN = crmTask.OwnerFQN;
                        cu = CRMGetUser(cu);
                        crmTask.OwnerId = cu.UserId;
                    }

                    if (!string.IsNullOrEmpty(crmTask.OwnerId.Trim()))
                    {
                        CRMEntityOwnership eo = new CRMEntityOwnership();
                        eo.Target = "task";
                        eo.TargetId = newtask.ToString();
                        eo.Assignee = crmTask.Owner.ToLower();
                        eo.AssigneeId = crmTask.OwnerId;
                        CRMChangeOwner(eo);
                    }

                    crmTask.Id = newtask.ToString();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return crmTask;
        }
 public CRMTask CRMCreateTask(CRMTask crmTask)
 {
     CRMFunctions function = new CRMFunctions(crmTask.Config);
     return function.CRMCreateTask(crmTask);
 }
Esempio n. 3
0
        public CRMTask CRMCreateTask(CRMTask crmTask)
        {
            OrganizationServiceProxy _serviceProxy;
            IOrganizationService     _service;
            string          res            = "";
            List <CRMState> returnEntities = new List <CRMState>();

            using (_serviceProxy = GetCRMConnection())
            {
                // This statement is required to enable early-bound type support.
                _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

                _service = (IOrganizationService)_serviceProxy;

                try
                {
                    Entity task = new Entity();
                    task.LogicalName    = "task";
                    task["subject"]     = crmTask.Subject;
                    task["description"] = crmTask.Description;
                    task["category"]    = crmTask.Category;
                    task["subcategory"] = crmTask.Subcategory;
                    if (!string.IsNullOrEmpty(crmTask.RegardingId.Trim()) && !string.IsNullOrEmpty(crmTask.Regarding.Trim()))
                    {
                        task["regardingobjectid"] = new EntityReference(crmTask.Regarding.ToLower(), new Guid(crmTask.RegardingId));
                    }

                    // assumes that the K2 CRM solution has been deployed
                    task["k2_k2serialnumber"]      = crmTask.K2SerialNumber;
                    task["k2_k2activityname"]      = crmTask.K2ActivityName;
                    task["k2_k2processname"]       = crmTask.K2ProcessName;
                    task["k2_k2processinstanceid"] = crmTask.K2ProcessInstanceId;

                    task["scheduleddurationminutes"] = crmTask.Duration;
                    task["scheduledend"]             = crmTask.DueDate;
                    task["prioritycode"]             = new OptionSetValue(crmTask.Priority);
                    task["statecode"]  = new OptionSetValue(crmTask.State);
                    task["statuscode"] = new OptionSetValue(crmTask.Status);

                    Guid newtask = _service.Create(task);

                    crmTask.Id = newtask.ToString();

                    if (string.IsNullOrEmpty(crmTask.OwnerId.Trim()) && !string.IsNullOrEmpty(crmTask.OwnerFQN.Trim()))
                    {
                        CRMUser cu = new CRMUser();
                        cu.UserFQN      = crmTask.OwnerFQN;
                        cu              = CRMGetUser(cu);
                        crmTask.OwnerId = cu.UserId;
                    }

                    if (!string.IsNullOrEmpty(crmTask.OwnerId.Trim()))
                    {
                        CRMEntityOwnership eo = new CRMEntityOwnership();
                        eo.Target     = "task";
                        eo.TargetId   = newtask.ToString();
                        eo.Assignee   = crmTask.Owner.ToLower();
                        eo.AssigneeId = crmTask.OwnerId;
                        CRMChangeOwner(eo);
                    }

                    crmTask.Id = newtask.ToString();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return(crmTask);
        }