K2Mng and K2ROM

  • 29 February 2008
  • 8 replies
  • 1 view

Badge +2

I have a .Net application that facilitates redirecting a worklist item.  Basically all Worklist items are listed using K2Mng and the GetWorklistItems method.  When the user selects the item to be redirected I use RedirectWorklistItem to move the item to the new user. 


I now need to update a process datafield for the process instance that the worklist item represents.  As far as I can tell I need to use K2ROM to do this, as K2Mng has no access to process data fields.  What is the best way to get a K2ROM processInstance from a K2Mng WorklistItem?


8 replies

Badge +2

I can get this to work, but it seems very loose, and relies on a the process instance having a unique Folio (which I do).



  • Use K2Mng GetWorkListItems
  • Use K2Mng.GetProcessInstances and find the process with the matching folio
  • Use K2ROM.OpenProcessInstance using the processID from above

As I said this works, but seems a little "loose".  Is there a better way?


What would I do If my folio values where not unique?


 

Badge +3

TM01, this is just a guess, but i think you can just use the value of the K2Mng.WorklistItem.ID as if it were the same exact thing as the K2ROM.WorklistItem.SerialNumber


So, take the value from you call K2Manager.RedirectWorklistItem(worklistItem.ID, strDestUser)


and just use that same value in the K2ROM.Connection.OpenWorklistItem(worklistItem.ID, etc. etc.)


i'm mixing my syntax here because you'd need to create a connection object first in K2ROM, it's not a static method, but you probably get the point since you using the API already.


here's what i'm basing my guess on:


if you take a look at the K2 database (and this is on K2.net 2003 sp2a, by the way) you'll find a couple of stored procedures that pretty much mimc the API interface.


CREATE PROCEDURE kWorklistItemRedirect @ProcInstID INT, @EventInstID INT, @User NVARCHAR(128) 


CREATE PROCEDURE kWorklistItemOpen @ProcInstID INT, @EventInstID INT, @Platform NVARCHAR(128), @Alloc BIT, @IgnoreStatus BIT


the parameters of these sprocs are so close to the API that i can only assume they match up and that the SerialNumber in K2 is just a ProcInstID and an EventInstID concatenated and split up by the API before making the db call.


that would lead me to believe you can just use the worklistitem.ID as a worklistItem.SerialNumber and get that connection you're looking for.


hope that helps.


 

Badge +2

Thanks, but there is no K2ROM OpenWorkListItem that takes an ID  as a parameter (not that I can find anyway).


 I have managed to find out the the ID returned for a worklist item vvia the K2ROM is the same as the the ID of the same process returned via K2Mng - I guess that should be expected.  Just no way of accessing via this ID in K2ROM (except opening the worklist of the user, and looping until I find the ID).


 


 

Badge +3

TM01 -- you're right, it was my bad guess. 


the following code is tested and confirms your last post.  it seems the only way to get at this ID would be to loop through all worklist items though.


 


k2rom_conn = new SourceCode.K2ROM.Connection();
k2rom_conn.Open("k2megasrv");
   
foreach (K2ROM.WorklistItem wli in k2rom_conn.OpenWorklist("ASP"))
{
    int id = wli.ID;
}
   
k2mng_conn = new SourceCode.K2Mng.K2Manager();
k2mng_conn.Login("k2megasrv",5252);


foreach (K2MNG.WorkListItem wli in k2mng_conn.GetWorkListItems("k2megaadministrator","","","","",null,null))
{
    long id2 = wli.ID;
}

Badge +3
TM01 -- just another thought ... K2ROM.WorklistItem has a redirect method directly on that class.  Could you not use that instead of the K2MNG namespace to do your redirecting?
Badge +4

K2ROM has a method called OpenWorklist() which can take in a WorklistCriteria filter. This makes it so you don't have to retrieve all items and then iterate. Folio is one of the options to filter on, but in the event folio isn't unique you can use a bunch of other things (like process id). It is also quite powerful because you can filter on multiple values, etc.


An example of this would be:

K2ROM.Connection conn = <open the connection, etc> 
int processId = 418;

K2ROM.WorklistCriteria criteria =
new K2ROM.WorklistCriteria();
criteria.Platform = "ASP";
criteria.NoData = true;

criteria.AddFilterField(K2ROM.WCField.ProcessID,
K2ROM.WCCompare.Equal, processId);

K2ROM.Worklist list = conn.OpenWorklist(criteria);

foreach( WorklistItem item in list )
{
//Do whatever you need to do to the items that matched your filter
}
Badge +13

 

Public Property

 NoData

WorklistItem objects returned in the
collection will be loaded with no process or activity data.
Setting this to true will have a direct impact on performance during the
retrieval of the collection

FYI, setting it to true would be faster but would not be able to access these when you loop through the WorkItems.

Default is false. 

oWorkListItem.ProcessInstance.DataFields("fieldname1").Value.ToString 

oWorkListItem.ProcessInstance.XmlFields("FormData").Value 

Badge +4

Correct.


 In the case where you are just doing redirects (such as in this post) or something that doesn't require access to datafields/xmlfields then setting NoData = true is more performant, but when you actually need to do something to the process/activity data then you should set this to false (or not set it at all since false is the default).

Reply