Skip to main content


 

Symptoms

 


I planned to use SourceCode.Workflow.Management.WorkflowManagementServer to retrieve a collection of Process Instances that were associated with a specific entity (as defined in the DataFields). From what I could see based on information from the internet I could not receive Process Instances for workflows where their status is completed. In order to display the full list of Process Instances I changed my method to access the information from the K2 database (using ServerLog.ProcInst table). This is working fine, however I would like to retrieve the URL to the viewflow for the completed tasks but I am unsure how to do this. When I attempt to retrieve the Process Instance (calling OpenProcessInstance() method using SourceCode.Workflow.Client.Connection) I get an error that the Process Instance does not exist. Is there an API or methods available for me to retrieve all Process Instances whether the statuses are open or closed? I'd like to get away from using a direct Query into the K2 database to get the information I need.
 

 

Diagnoses

 


The 'SourceCode.Workflow.Management.WorkflowManagementServer' API will only return ACTIVE instances. COMPLETED process instances are moved to the ServerLog.ProcInst table and can only be reported against.
 

 

Resolution

One way to achieve this is using a reporting SmartObject.

 

Below is a sample code snippet for reference:

 

 

 

--Begin

 

 

 

SourceCode.SmartObjects.Client.SmartObjectClientServer serverName = new SourceCode.SmartObjects.Client.SmartObjectClientServer() SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder() // build a connection string connectionString.Authenticate = true connectionString.Host = "localhost" connectionString.Integrated = true connectionString.IsPrimaryLogin = true connectionString.Port = 5555 // open a K2 Server connection serverName.CreateConnection() serverName.Connection.Open(connectionString.ToString()) try { // get a handle to the SmartObject SourceCode.SmartObjects.Client.SmartObject smartObject = serverName.GetSmartObject("Activity_Instance_Destination") // specify which method will be called smartObject.MethodToExecute = "List" // specify input parameters for the method smartObject.Propertiese"ProcessFolder"].Value = "FolderName" smartObject.Propertiese"ProcessName"].Value = "Process1" smartObject.Propertiese"Status"].Value = "Completed" smartObject.Propertiese"Destination"].Value = "user account" // call the method SourceCode.SmartObjects.Client.SmartObjectList oSmOList = serverName.ExecuteList(smartObject) DataTable dt = new DataTable() dt.Columns.Add("Step Name") dt.Columns.Add("Owner") dt.Columns.Add("Action") dt.Columns.Add("Start Date") dt.Columns.Add("Finish Date") // iterate each smartobject in the collection and do something with the data foreach (SourceCode.SmartObjects.Client.SmartObject oSmO in oSmOList.SmartObjectsList) { DataRow dr = dt.NewRow() drd"Step Name"] = oSmO.PropertiesS"ActivityName"].Value.ToString() dr."Owner"] = oSmO.PropertiesS"Destination"].Value.ToString() dr."Action"] = oSmO.PropertiesS"Final_Action"].Value.ToString() dr."Start Date"] = oSmO.PropertiesS"StartDate"].Value.ToString() dr."Finish Date"] = oSmO.PropertiesS"FinishDate"].Value.ToString() dt.Rows.Add(dr) } GridView1.DataSource = dt.DefaultView GridView1.DataBind()

 

 

 

--End

 

 



 
Be the first to reply!

Reply