ProcessSet.LoadInstances method

  • 24 August 2007
  • 5 replies
  • 0 views

Badge +4

I have found some code in one of our applications that calls a ProcessSet.LoadInstances method. I can't find any reference to this method in the documentation, and I'm not sure what it does.


The code snippet is below, basically we just need to find a specific process instance but it seems as though there should be a more efficient way to do this. 


 


SourceCode.K2Mng.ProcessFolders PFolders = K2M.GetProcessFolders();


foreach(SourceCode.K2Mng.ProcessFolder PF in PFolders)


{


     foreach(SourceCode.K2Mng.ProcessSet ps in PF.ProcessSets)


    {


        ps.LoadInstances(K2M,"","","","");


        foreach(SourceCode.K2Mng.ProcessInstance pi in ps.Instances)


        {


             if (pi.Folio.ToUpper() == folio)


             {


                    // do stuff


             }


 


5 replies

Badge +9

I believe LoadInstances just populates the of ProcSet.Instances collection with K2Mng.ProcessInstance.  The parameters on the LoadInstances method allow you to filter the returned collection members.


 


 

Badge +5

Hi etp,


The could above is searching for a process instance.  You  can see it starts out at the Folder level, then looks at the ProcessSet (which is esentially Process + VersionNo) and then retrieves all current instances.  Finally it checks to see if the Folio field is equal to a parameter call "folio" and if so to // do stuff.


If you want to return a list of all process instances and have no need to do it in a hierarchal fashion simply call K2Manager.GetWorkListItems().  You'll notice it has various optional parameters that you can choose not to fill out.  You can find the K2Manager class documented within the K2 help file under references.


Let us know if you need any more assistance.


-mike

Badge +5

BTW,


Take note of the Login() and Logout() methods on the K2Manager class.  You'll need to Login before attempting any other action and need to Logout() when you are done.  You'll also need to login as a K2 Administrator so ensure the account run your code has the appropriate rights (ie your end users should not be running this code).


-mike

Badge +4

Thanks again Mike.


 We basically just need to get a specific process instance by process ID. I couldn't find a better/more direct wayof doing it than the above, although I feel there should be one.


In terms of the K2Mng vs K2Rom, I am aware of the recommendation that the K2Mng shouldn't be used in any end user applications. Unfortunately the K2Rom seems extremely limited and I have been using the K2Mng quite extensively in our current developement of end user applications.


The paticular module that uses the code above for example actually needs to delete the process instance, which I believe is not possible from the K2Rom.


It also seems that only a limited amount of process info is available from the K2Rom. For example I don't see how to find the process originator from the K2Rom. Similarly, I can't see any way to access the process datafields from the K2Mng. Because of this, many of our applications have to find and query the same process through both dlls to extract all the info we need. Although there is significant overlap between K2Mng process instances and K2Rom process instances, they appear essentially different objects and neither offers the full range of functionality that we would like.


Regarding admin rights, I believe that all users on a K2 installation are initially set as admins, and since I'm not aware that any user rights have ever been manually set by us I think its likely that every user in our company has retained their admin status (although I'm not sure of where/how to check this). So hopefully the applications using K2Mng should work, although I am aware that this is contrary to best practise and your recommend usage.


I would be very interested in your thoughts and recommendations on the above, as these issues are obviously a worry to us as relatively inexperienced K2 developers.

Badge +5

Your correct there's not a direct way to quickly call on a specific process instance by it's ID.  The most direct way to do this is to one of the four overloaded K2Manager.GetProcessInstances methods.  You'll notice that this returns a collection of ProcessInstances which you can interate over and check their ID property for the one your looking for.  You'll also be able to check the originator property to see who started the process.  Another property of interest might also be status.

Remeber that using the K2ROM is everything runtime, so the ROM is aware of all the datafields, xmlfields and contains methods with actually work on a task item like (Update and Finish).  Where the K2Mng is an API that is the foundation for the K2Service Manager (Start >> Programs >> K2.net 2003 >> K2.net 2003 Service Manager). Where performing management functionality you don't need all the data and xmlfields to load due to overhead.  Although there are times like now where it would be nice in some scenarios to have them.


You correct that it's not possible to delete a process instance from the K2ROM. You can however expire an activity and control the flow where it might go to a "Process Cancelled" activity in which you can do some clean work and maybe notify the necessary people of the cancellation.  You may consider this as a more elegant solution.  Also when considering how your want to implement this keep this litle trick in mind.  When you assign a task to your user(s) also assign the task to a Service Account, say, DOMAINK2ApplicationServer.  That way both your users who should be acting on the task(s) can but also, should the need arise your applicatio can programmatically access the task as well via the ROM and perform some of the other actions it sounds like you also need.


At the end of the day you'll probably need a little mix of both but it should get the jump down fairly easy.  Let us know if you need any other assistance.


-mike

Reply