Skip to main content

An interesting question arose:


 "Process Originators need a 'My Requests' worklist that displays unfinished process instances that the user has originated and allows them to 'cancel' if so desired..."


Here is one way to solve this problem using the hblackpearl] Workflow.Management API to issue a GotoActivity() .

Essentially, a list of all unfinished processes originated by UserA will be displayed in an aspx page.
In this code, there is a cancel link provided for each entry.
If the link is clicked on, process instance is interrogated to see if it contains a "Finish" activity
    If it does contain a "Finish" Activity -  GotoActivity("Finish") is issued.
    If it does not contain a "Finish" Activity - a message is displayed to the user explaining this.

This should help get you on your way to understanding how to instantiate the new Workflow.Management interface in addition to providing a way for the originator to cancel their workflow with reasonable elegance.


You will need to reference SourceCode.Workflow.Management in your project and have a div in your aspx page called divMessage...


Again, it will only successfully cancel processes that contain a "Finish" activity.

Create a page called RequestList.aspx and use the following code in the code behind:  don't forget to reference SourceCode.Workflow.Management and SourceCode.HostClientAPI


private string strProcessID = string.Empty;
protected void Page_Load(object sender, EventArgs e)
        {
            //declare a connection to the k2 management interface
            //modify this to include user/pass after port
            SourceCode.Workflow.Management.WorkflowManagementServer BPM = new SourceCode.Workflow.Management.WorkflowManagementServer("localhost",5555);
            BPM.Open();


                //If a process ID is passed, go ahead with GotoActivity command
                if (RequestI"ProcessID"] != null)
                {
                    strProcessID = Requeste"ProcessID"];
                }


                if (strProcessID != String.Empty)
                {
                    int intProcessID = Convert.ToInt32(strProcessID);
                   
                    //Provide status message with details regarding process being cancelled
                    divMessage.InnerHtml = "Process ID:<b>" + strProcessID + "</b>Selected for Cancel<br>";
                    //..
                    //..



                    //list activities check for one containing "Finish"
                    SourceCode.Workflow.Management.Activities Activities = BPM.GetProcActivities(intProcessID);


                    Boolean blFinishFound = false;


                   
                    foreach (SourceCode.Workflow.Management.Activity Activity in Activities) {
                       
                        if (Activity.Name == "Finish" && blFinishFound == false)
                        {
                            blFinishFound = true;
                           
                            BPM.GotoActivity(intProcessID, "Finish");
                            divMessage.InnerHtml = divMessage.InnerHtml + "Process cancelled successfully<br>";
                        }
                    }   
                    if (blFinishFound == false){
                        divMessage.InnerHtml = divMessage.InnerHtml + "No Finish Activity is available in the process - it cannot be cancelled via this method<br>";
                    }
                }
                //If no Process ID is passed, provide list of processes originated by the current user
                else
                {
                    //format the current user into a string for filtering the process they originated
                    string strFormattedCurrentUser = Convert.ToString("K2:" + HttpContext.Current.User.Identity.Name.ToString());


                    //Snag the process instance list
                    string strblank = string.Empty;
                    SourceCode.Workflow.Management.ProcessInstances processCollection = BPM.GetProcessInstancesAll(strblank, strblank, strFormattedCurrentUser);


                    //look for processes originated by the current user and not yet finished
                    foreach (SourceCode.Workflow.Management.ProcessInstance k2process in processCollection)
                    {
                       


                       
                            divMessage.InnerHtml = divMessage.InnerHtml + "<a href=requestlist.aspx?ProcessID=" + k2process.ID.ToString() + ">Cancel</a> ";
                            divMessage.InnerHtml = divMessage.InnerHtml + "<b>ID: </b>" + k2process.ID.ToString() + " | ";
                            divMessage.InnerHtml = divMessage.InnerHtml + "<b>Status: </b>" + k2process.Status.ToString() + " | ";
                            divMessage.InnerHtml = divMessage.InnerHtml + "<b>Folio: </b>" + k2process.Folio.ToString() + " | ";
                            divMessage.InnerHtml = divMessage.InnerHtml + "<b>Originator: </b>" + k2process.Originator.ToString() + " | <br>";
                       
                    }
                }
                BPM.Connection.Close();
         
       }


 


 


16845iBEA563746C2EE18C.png

Hi Joseph,


What's the security requirement of the Virtual Directory hosting this page?


Should we need to configure to windows authentication and set impersonation to false?


And should we set the Identity Account for the Application Pool to a AD account that has K2 Server Admin right?


These may helps other to set up your web page right first time :-) 


Many thanks,


Marco


Reply