/// <summary> /// Starts a workflow /// </summary> /// <param name="Folio"></param> /// <param name="ProcessName"></param> /// <returns></returns> public int StartProcess(string Folio, string ProcessName) { var con = ConfigurationManager.AppSettings; int ProcessInstanceId = 0; SourceCode.Workflow.Client.Connection K2Conn = new SourceCode.Workflow.Client.Connection(); K2Conn.Open(servername); try { SourceCode.Workflow.Client.ProcessInstance K2Proc = K2Conn.CreateProcessInstance(ProcessName); K2Proc.Folio = Folio; K2Conn.ImpersonateUser(ServiceAccount); K2Conn.StartProcessInstance(K2Proc); ProcessInstanceId = K2Proc.ID; } catch (Exception EX) { ProcessInstanceId = 0; } finally { K2Conn.Close(); } return(ProcessInstanceId); }
/// <summary> /// Task Details /// </summary> /// <param name="serialnumber"></param> /// <param name="destination"></param> /// <returns></returns> public List <TaskDetails> OpenTask(string serialnumber, string destination) { List <TaskDetails> list = new List <TaskDetails>(); SourceCode.Workflow.Client.Connection K2Conn = new SourceCode.Workflow.Client.Connection(); K2Conn.Open(servername); K2Conn.ImpersonateUser(destination); SourceCode.Workflow.Client.WorklistItem K2WListItem = K2Conn.OpenWorklistItem(serialnumber); try { list.Add(new TaskDetails { Status = K2WListItem.Status.ToString(), SerialNumber = K2WListItem.SerialNumber, Actions = K2WListItem.Actions, Data = K2WListItem.Data, DataFields = K2WListItem.ProcessInstance.DataFields.ToString() }); K2WListItem.Release(); } catch (Exception ex) { list.Add(new TaskDetails { Status = "No Task" }); } finally { K2Conn.Close(); } return(list); }
/// <summary> /// Actions a task /// </summary> /// <param name="action"></param> /// <param name="serialnumber"></param> /// <param name="destinationuser"></param> /// <returns></returns> public Boolean ActionTask(string action, string serialnumber, string destinationuser) { Boolean result = false; SourceCode.Workflow.Client.Connection K2Conn = new SourceCode.Workflow.Client.Connection(); K2Conn.Open(servername); K2Conn.ImpersonateUser(destinationuser); SourceCode.Workflow.Client.WorklistItem K2WListItem = K2Conn.OpenWorklistItem(serialnumber); try { K2WListItem.Actions[action].Execute(); result = true; } catch (Exception ex) { result = false; } finally { K2Conn.Close(); } return(result); }
private void GetK2OpenConnection(string userAccount) { conn = new SourceCode.Workflow.Client.Connection(); conn.Open(K2Server, this.K2AdminConnection); conn.ImpersonateUser(userAccount); }