private void UpdateCRMTask_ExecuteCode(object sender, EventArgs e)
        {
            XmlDocument tasks = new XmlDocument();

            tasks.LoadXml(K2.ProcessInstance.XmlFields["CRM Tasks"].Value);
            XmlNode taskidNode = tasks.SelectSingleNode("/CRMTasks/Task[SerialNumber= '" + K2.ProcessInstance.ID + "_" + K2.EventInstance.ActivityInstanceDestination.ID + "']/TaskId");

            if (taskidNode != null)
            {
                try
                {
                    using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer))
                    {
                        SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(K2.Configuration.CRMFunctionsSmartObject);

                        SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "SetStateStatus");

                        smartObject.Properties["Entity"].Value   = "task";
                        smartObject.Properties["EntityId"].Value = taskidNode.InnerText;
                        smartObject.Properties["State"].Value    = "1";
                        smartObject.Properties["Status"].Value   = "5";

                        SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod);
                    }
                }
                catch (Exception ex)
                {
                    K2.ProcessInstance.Logger.LogErrorMessage("CRM Client Event - Completing task", ex.Message);
                }
            }
        }
Esempio n. 2
0
        public void Main($contexttype$ K2)
        {
            try
            {
                using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer))
                {
                    SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(K2.Configuration.CRMFunctionsSmartObject);

                    SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "BulkActionTasksSetCriteria");

                    smartObject.Properties["FromState"].Value  = "0";
                    smartObject.Properties["FromStatus"].Value = "3";
                    smartObject.Properties["ToState"].Value    = "2";
                    smartObject.Properties["ToStatus"].Value   = "6";
                    //smartObject.Properties["Regarding"].Value = K2.Configuration.CRMEntityType;
                    //smartObject.Properties["RegardingId"].Value = K2.Configuration.CRMEntityId; ;
                    smartObject.Properties["K2ProcessName"].Value       = K2.ProcessInstance.Process.Name;
                    smartObject.Properties["K2ProcessInstanceId"].Value = K2.ProcessInstance.ID.ToString();

                    SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod);
                }
            }
            catch (Exception ex)
            {
                K2.ProcessInstance.Logger.LogErrorMessage("CRM Client Finish Rule", ex.Message);
            }
        }
Esempio n. 3
0
        public void Main($contexttype$ K2)
        {
            if (SucceedingRuleHelper.AnyOutcomesEvaluatedSuccessfully(K2))
            {
                try
                {
                    using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer))
                    {
                        SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(K2.Configuration.CRMFunctionsSmartObject);

                        SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "BulkActionTasksSetCriteria");

                        smartObject.Properties["FromState"].Value           = "0";
                        smartObject.Properties["FromStatus"].Value          = "3";
                        smartObject.Properties["ToState"].Value             = "2";
                        smartObject.Properties["ToStatus"].Value            = "6";
                        smartObject.Properties["Regarding"].Value           = K2.Configuration.CRMEntityType;
                        smartObject.Properties["RegardingId"].Value         = K2.Configuration.CRMEntityId;;
                        smartObject.Properties["K2ActivityName"].Value      = K2.ActivityInstance.Activity.Name;
                        smartObject.Properties["K2ProcessName"].Value       = K2.ProcessInstance.Process.Name;
                        smartObject.Properties["K2ProcessInstanceId"].Value = K2.ProcessInstance.ID.ToString();

                        SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod);
                        K2.SucceedingRule = true;
                    }
                }
                catch (Exception ex)
                {
                    K2.ProcessInstance.Logger.LogErrorMessage("CRM Client Event - Completing task", ex.Message);
                }
            }
            else
            {
                K2.SucceedingRule = false;
            }
        }
Esempio n. 4
0
        public void Main($contexttype$ K2)
        {
            string strURL = string.Empty;

            string smartObjectName = K2.Configuration.CRMFunctionsSmartObject;

            try
            {
                using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer))
                {
                    SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(smartObjectName);

                    SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "GetEntityMetadata");

                    SourceCode.SmartObjects.Client.SmartProperty logicalEntitName = smartMethod.InputProperties["EntityLogicalName"];
                    logicalEntitName.Value = K2.Configuration.CRMEntityType.ToLower();

                    SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod);

                    if (string.IsNullOrEmpty(K2.Configuration.CRMFormURL.Trim()))
                    {
                        string extraqs = string.Empty;

                        if (!string.IsNullOrEmpty(K2.Configuration.CRMEntityForm.Trim()))
                        {
                            extraqs = "&extraqs=formid%3d" + K2.Configuration.CRMEntityForm;
                        }
                        if (!string.IsNullOrEmpty(K2.Configuration.CRMCustomSNParameter.Trim()))
                        {
                            if (string.IsNullOrEmpty(extraqs))
                            {
                                extraqs = "&extraqs=" + K2.Configuration.CRMCustomSNParameter + "%3d" + K2.SerialNumber;
                            }
                            else
                            {
                                extraqs = extraqs + "%26" + K2.Configuration.CRMCustomSNParameter + "%3d" + K2.SerialNumber;
                            }
                        }
                        strURL = CheckCRMURL(K2.Configuration.CRMServerURL) + K2.Configuration.CRMOrganisation + "/main.aspx?etc=" + smo.Properties["EntityObjectTypeCode"].Value + extraqs + "&id=" + K2.Configuration.CRMEntityId + "&pagetype=entityrecord";
                    }
                    else
                    {
                        strURL = K2.Configuration.CRMFormURL;
                    }

                    smartObject.Dispose();
                    smartObject = null;
                    smartMethod.Dispose();
                    smartMethod = null;

                    smartObject = smartObjects.GetSmartObject(smartObjectName);
                    smartMethod = smartObjects.GetSingleMethod(smartObject, "CreateTask");

                    DateTime due = new DateTime();

                    smartObject.Properties["Category"].Value            = K2.Configuration.TaskCategory;
                    smartObject.Properties["Description"].Value         = K2.Configuration.TaskDescription;
                    smartObject.Properties["DueDate"].Value             = DateTime.TryParse(K2.Configuration.TaskDueDate, out due) ? DateTime.Parse(K2.Configuration.TaskDueDate).ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.Add(new TimeSpan(3, 0, 0, 0)).ToString("yyyy-MM-dd HH:mm:ss");
                    smartObject.Properties["Duration"].Value            = string.IsNullOrEmpty(K2.Configuration.TaskDuration) ? "0" : K2.Configuration.TaskDuration;
                    smartObject.Properties["OwnerFQN"].Value            = K2.ActivityInstanceDestination.User.Name.Replace("K2:", "").Replace("k2:", ""); //K2.Configuration.TaskOwnerFQN.Replace("K2:", "").Replace("k2:", "");
                    smartObject.Properties["OwnerId"].Value             = K2.Configuration.TaskOwnerId;
                    smartObject.Properties["Owner"].Value               = K2.Configuration.TaskOwner.Replace("K2:", "").Replace("k2:", "");
                    smartObject.Properties["Priority"].Value            = string.IsNullOrEmpty(K2.Configuration.TaskPriority) ? "1" : K2.Configuration.TaskPriority;
                    smartObject.Properties["Regarding"].Value           = K2.Configuration.TaskRegarding;
                    smartObject.Properties["RegardingId"].Value         = K2.Configuration.TaskRegardingId;
                    smartObject.Properties["State"].Value               = string.IsNullOrEmpty(K2.Configuration.TaskState) ? "0" : K2.Configuration.TaskState;
                    smartObject.Properties["Status"].Value              = string.IsNullOrEmpty(K2.Configuration.TaskStatus) ? "3" : K2.Configuration.TaskStatus;
                    smartObject.Properties["Subcategory"].Value         = K2.Configuration.TaskSubcategory;
                    smartObject.Properties["Subject"].Value             = K2.Configuration.TaskSubject;
                    smartObject.Properties["K2SerialNumber"].Value      = K2.SerialNumber;
                    smartObject.Properties["K2ActivityName"].Value      = K2.ActivityInstanceDestination.Activity.Name;
                    smartObject.Properties["K2ProcessName"].Value       = K2.ProcessInstance.Process.Name;
                    smartObject.Properties["K2ProcessInstanceId"].Value = K2.ProcessInstance.ID.ToString();

                    smo = smartObjects.ExecuteSingleMethod(smartMethod);

                    XmlDocument tasks = new XmlDocument();
                    tasks.LoadXml(K2.ProcessInstance.XmlFields["CRM Tasks"].Value);

                    string newtask = "<Task><TaskId>" + smo.Properties["TaskId"].Value + "</TaskId><SerialNumber>" + K2.SerialNumber + "</SerialNumber><DestinationUser>" + K2.Configuration.TaskOwnerFQN + "</DestinationUser><Process>" + K2.Configuration.ProcessName + "</Process><Activity>" + K2.Configuration.ActivityName + "</Activity></Task>";
                    //string newtask = "<Task><Guid>" + taskresponse.Data.Id + "</Guid><SerialNumber>" + K2.SerialNumber + "</SerialNumber><DestinationUser>" + K2.Configuration.TaskOwnerFQN + "</DestinationUser><Process></Process><Activity></Activity></Task>";

                    tasks.FirstChild.InnerXml += newtask;

                    K2.ProcessInstance.XmlFields["CRM Tasks"].Value = tasks.OuterXml;

                    K2.AddWorklist(K2.Configuration.InternetPlatform, System.Web.HttpUtility.UrlPathEncode(strURL));
                }
            }
            catch (Exception ex)
            {
                K2.ProcessInstance.Logger.LogErrorMessage(K2.Event.Name, ex.Message);
            }
        }