How to get the count of Worklist using K2 wcf service?


Badge +1
We are using OpenWorklistFiltered method of K2 wcf service to get a list of worklistitems based on some criteria. We have requirement to show the count of worklistitems based on various criterion. Is there any way to get the count of records returned without getting the actual records back? We used the similar kind of functionality using the K2 API using TotalCount property for WorkList class. But we could not find any such method for worklistitems using wcf service. Please do let us know how to proceed on that.

10 replies

Badge +9

If you go to help.k2.com and search up 'WCF Services' and look at the methods and you'll see that there isn't one for what you want. I would link it directly, but lithium doesn't like the link.

Badge +5

I don't see any way to get the count without returning all the users themselves either. Seems like there should be, hmm.

Badge +1

So what could be the best possible alternative for this?

Badge +9

You're going to have to write your own piece of code that takes in the work list items as an array and then element counts.

Badge +1

Thanks for the reply. But that would fetch all the worklist item values even if we need just the count. Doesn't sound too efficient. Can we achieve the same through any OOB smartobject services?

Badge +9

Maybe......let me check some stuff.

Badge +9

Pretty sure the answer is no for out of box. But you might be able to cook something up using the Workflow Management API. But even then you'll still be returning a collection of Worklist Items and then filtering against those and I am pretty sure what you are trying to get is some integer value.

Badge +9

PAUSE everything.....idea is had.

Badge +9

Yes, we can get a count. In SQL Server Management Sutdio in the K2 DB there is a table named ServerLog.ProcInst. Within that table lay the ghosts of WorkFlows past as well as all active workflows. Now, the ID field is what's doing the counting so you can snage the IDs and take the largest one and that would be the count. No if you wanted only active processes then you would need to make a new table in which you filter the ServerLog.ProcInst table based on status (a status of 2 represents active and if you look at the ServerLog.Status table it defines all the statuses) if you made script to filter ProcInst table into a new table based on whether an element is active or not you would get a new table with all the active processes and the new ID field would fucntion as your count.

Badge +1

Sorry for the late reply.

Thanks Austin. That is a great solution. But we are a bit hesitant to directly access the K2 database. I happened to stumble upon a method in smart object : SmartObjectClientServer.GetNumberOfRecords(smartObject) . It serves my purpose. But somehow it is too slow  for any practical purpose. Even if 0 records found, it is taking an average time of 20 seconds plus to return the message. Is there any way to optimize the method's performance?

Reply