Help on Deleting a ProcessInstance thru C#/K2ROM/K2MNG code

  • 22 October 2007
  • 7 replies
  • 2 views

Badge +1

Hi All,


I have an existing code that would delete a ProcessInstances thru SQL, I'm just wondering if there are any existing code that I can use without hitting directly in the K2Log and K2 DB. I'm thinking of using K2ROM or K2MNG thru WebService. Is this feasible?


Your help will be much appreciated.


Thanks in advance!


-ginoskie m/


7 replies

Badge +10

The one thing not shown here is adding of the reference to C:Program FilesK2.net 2003BinK2Mng.dll.


You’ll notice that this was used within a WinForm app (you’ll see me changing the cursor and prompting with message boxes and retrieving data from controls), but it should be fairly straightforward to retrofit if needed.
     


 



private void DeleteAllProcessInstances()
            {
                  this.Cursor = Cursors.WaitCursor;
                  K2Manager oMgr = new K2Manager();


                  string strProcess = txtFullProcessName.Text;


                  // K2Mng requires user to be a K2 Server Admin.  If the current user
                  // context is not a K2 admin, a connection string can be passed in
                  // the 3rd parameter below in the form of "Domain Name,User ID, pwd")
                  bool bRet = oMgr.Login(txtK2Server.Text, 5252, "");


                  int nDeletedInsts = 0;
                  if (bRet)
                  {
                        ProcessSets oSets = oMgr.GetProcSets();


                        foreach (ProcessSet oSet in oSets)
                        {
                              if (oSet.FullName.ToUpper() == strProcess.ToUpper())
                              {
                                    ProcessInstances oInsts = oMgr.GetProcessInstances(oSet.ProcID);


                                    int nCnt = oInsts.Count;


                                    if(nCnt > 0)
                                    {
                                          if (MessageBox.Show("Are you sure you want to delete the " + nCnt.ToString() + " active process instances?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                          {
                                                for(int x = 0; x < nCnt; x++)
                                                {
                                                      long nProcID = oInsts.ID;
                                                      if (oMgr.DeleteProcessInstances(nProcID, true))
                                                      {
                                                            nDeletedInsts++;
                                                      }
                                                }
                                          }
                                    }
                              }
                        }
                  }
                  else
                  {
                        MessageBox.Show("Not able to log into server.");
                  }


                  MessageBox.Show(nDeletedInsts.ToString() + " process instances deleted.");


                  this.Cursor = Cursors.Default;
            }

Badge +13
Does this work to delete completed items?   I know from K2 Service Manager you can delete this plus the log, but it only allows you to do it for active workitems.
Badge +9

K2MNG (which is used by this code sample) will only work on currently active process instances, just like K2 Service Manager.  There is no API method to delete completed process instances.


 

Badge +9

You may also consider the K2.net 2003 Database CleanUp sql scripts available from K2 technical support. Please note they are only recommended for development use. In other words, deleting processes on a production server is not supported.

Badge +1

Thanks a lot chrisg, peter and bob!


This will really help a lot to me! =)


- ginoskie

Badge +1

Hi All,


 Just have an additional question is there any way I can get a Datafield values through K2MNG?


 Thanks again!


 -ginoskie

Badge +9
Unfortunately there is no way to get datafield values through K2MNG.  However if you are using K2MNG I assume you are using custom .NET code, so you should be able to leverage the K2 reporting webservice to programmatically get those values.  KB 21 (http://kb.k2workflow.com/articles/kb000021.aspx) provides insight and code sample of how to interact with this webservice (called FilterService).

Reply