Question

C# COM API - Get Worklist Items Including Out Of Office Items

  • 27 July 2020
  • 1 reply
  • 79 views

Hi All,

 

We had an issue last week which I want to share the solution with here, in the hope that it may help other people in the future.

 

We have a custom MVC website, part of which has a grid view of the users outstanding K2 Work Item tasks. We use the COM DLLs to get these items using the code:

 

Connection k2Conn = new Connection() ;

k2Conn.Open([K2 Server]);

var workItems = k2Conn.OpenWorklist();

 

This was working well, however when it was mentioned that someone wanted to start using the K2 Out Of Office feature we ran some tests and realised that this wasn't returning the items that have been delegated to the logged in user. For example if Anna is going on annual leave and assigns her out of office to Barry, when Barry loads his custom worklist he isn't seeing Anna's items when he should do (despite being able to see them when using the standard K2 worklist). 

 

We reached out to K2 support about this, and eventually they sent us the following code back which makes sure that we get these items is:

 

Connection k2Conn = new Connection() ;

k2Conn.Open([K2 Server]);

WorklistCriteria criteria = new WorklistCriteria();
criteria.Platform = "ASP";
criteria.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Me", WCCompare.Equal, WCWorklistItemOwner.Me);
criteria.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Other", WCCompare.Equal, WCWorklistItemOwner.Other); // Returns OOF/Shared tasks as well

var workItems = k2Conn.OpenWorklist();

 

Doing this then gave us the full list back as we were expecting. However, we then encountered an additional problem. When putting the page together we are using the WorklistItem.Data property to know the URL to open for the worklist item (for example https://k2servername//Runtime/Runtime/Form/Task.Review/?SerialNo=1234_56). Again this was working correctly for the users own tasks, however when we then trying to open delegated tasks we were getting an error #24411 (saying the user doesn't have authority to open the task). We attempted to use the OpenWorklistItem() and OpenSharedWorklistItem() methods which we hadn't originally implemented to see if that was what we were missing, but that still didn't resolve the issue. 

 

We eventually realised that the issue was that to open a delegated task, you need to append the parameter 'SharedUserName' with the values of the username of the original user to the end of the URL. I.e.

https://k2servername//Runtime/Runtime/Form/Task.Review/?SerialNo=1234_56 becomes:

https://k2servername//Runtime/Runtime/Form/Task.Review/?SerialNo=1234_56&SharedUser=AnnaC

 

Hopefully that helps someone in the future who may be stuck in a similar way!


1 reply

Userlevel 1
Badge +3

Hi joshua_geldards,


 


Thank you for sharing this information with the community!


 


Kent

Reply