How to query the completed workflow instance

  • 22 July 2011
  • 7 replies
  • 3 views

Badge +3

hello,


i have scenario that need query all workflow instances in workflow. for example, when the user login sharepoint site, he could see work list 1, this worklist would display all active instances now pending his action.


also he wanted to see all the instances he have already taken actions(like approve) in another work list 2.  so that is the case.


we know we must develop a new work list, but we don't know how to read the instances that is completed by the current user.


could you please give me some helps?


Thanks,


  


7 replies

Badge +5

Off the top of my head you could query the Activity Instance Audit SmartObject and filter by Process Name and User name?

Badge +3

hello, could you please give me some guides or documents on this topic? i don't know how to do this


any help appreciated

Badge +5

Hi Ruciffa,


I assume you want to do this in code, so here's how you'd do it.


First of all, make a connection to the SmartObject server using port 5555 (Google SCConnectionStringBuilder for examples). Open this connection, and then you need to load up the SmartObject, filter it and execute the method. Here's some code (I haven't compiled this so it may not work):


            var smartObjectClientServer = new SmartObjectClientServer();


            var cb = new SCConnectionStringBuilder
            {
                // Set up your connection values
            };



            using (BaseAPIConnection conn = smartObjectClientServer.CreateConnection())
            {
                conn.Open(cb.ToString());
               
                var dataAuditSmartObjectDefinition = smartObjectClientServer.GetSmartObject("Activity_Instance_Audit");
                dataAuditSmartObjectDefinition.MethodToExecute = "List";
                dataAuditSmartObjectDefinition.Properties["Process_Name"].Value = "Your process name";
                dataAuditSmartObjectDefinition.Properties["User_Name"].Value = "Your username";
                var results = smartObjectClientServer.ExecuteList(dataAuditSmartObjectDefinition);
            }


the results variable wqill now contain a list of SmartObjects. Loop through these and you can read the values like a dictionary, i.e. smartObject.Properties["User_Name"].Value etc


Hope that helps?


 

Badge +3

hello, Trentino,


Thanks for your help.


By the help, we can query the information of completed instance now. although there is no a smart object of "Activity_Instance_Audit" in our server.


we use "Activity_Instance_Destination" instead,  the result seems ok, is there any difference?


the code sample is as below, hope this can help the others who also met this problem:


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.Properties["ProcessFolder"].Value = "FolderName";
                smartObject.Properties["ProcessName"].Value = "Process1";
                smartObject.Properties["Status"].Value = "Completed";
                smartObject.Properties["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();
                    dr["Step Name"] = oSmO.Properties["ActivityName"].Value.ToString();
                    dr["Owner"] = oSmO.Properties["Destination"].Value.ToString();
                    dr["Action"] = oSmO.Properties["Final_Action"].Value.ToString();
                    dr["Start Date"] = oSmO.Properties["StartDate"].Value.ToString();
                    dr["Finish Date"] = oSmO.Properties["FinishDate"].Value.ToString();


                    dt.Rows.Add(dr);


                }


                GridView1.DataSource = dt.DefaultView;
                GridView1.DataBind();


 


Thanks again for your help.


Best Regards,


 

Badge +3

hello, another question


to getting some datafields in the same workflow instance, i use the processID i queried in the code above to open the process in K2 Server, but failed.  it seems it's different to get datafield between the active instance and completed instance, it's said this process is not found, i queried the process id from :


processInstanceId = oSmO.Properties["ProcessInstanceID"].Value.ToString();


and use this code to read data field


Connection conn = new Connection();


            //create connection string
            SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder builder = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();


            builder.Host = "localhost";
            builder.Port = 5252;
            builder.SecurityLabelName = "K2";
            builder.Authenticate = true;
            builder.IsPrimaryLogin = true;
            builder.Integrated = true;


            // Connect to Workflow Server
            conn.Open("localhost", builder.ConnectionString);


ProcessInstance pi = conn.OpenProcessInstance(Int32.Parse(processInstanceId));


                    dr["Stage"] = pi.DataFields["DDLStage"].Value.ToString();
                    dr["Testing Program Name"] = pi.DataFields["TBTestingProgramName"].Value.ToString();


How to query the data field of the same instance in this scenario ?

Badge

Hi Ruciffa,


I have the same query as yours, could you please help me out in finding the "SourceCode.SmartObjects.Client.SmartObject" API as I'm unable to locate this.


Thanks in advance.


Regards,


Ravi


 

Badge +10

Hi,


Keep in mind that the reporting SmartObjects will return data on Active and Completed Process Instances. Your code above only makes use of the Workflow.Client API and therefore will only work if the process is still active. This code will not work for process instances which were completed. Also note that the OpenProcessInstance method requires the executing user to be an Admin on the Process definition.


A better approach here would be to use the Reporting SmartObjects to get the Data Field values. There is a SmartObject called Activity_Data which you can use for this purpose. It has a Process Instance ID field which you can use to filter the results. This will work for active and completed instances. The only prerequisite is that the executing user needs to have View or View Participate rights to view the results. (If you are using View Participate, the executing user must have been a destination or the originator of the process)


I hope this helps!

Reply