Skip to main content

Is there a way to action a worklist item as a service account via a button click on a form even  if that service account is added as a recipient to a task but the person clicking the button is not?

 

For example, I have a button on a form that someone can click who isn't assigned to the task that that button is actioning. I do a search for the task serial number specific to the service account who is assigned the task. The logic works like a charm. However, when the button is clicked by an end user and the workflist action is taken, K2 is saying that the current user (who is not the service account) does not have the rights to action the task.

 

I want to know how can I get around this error? Is there a way to impersonate my service account or the button click, or the action a worklist item rule so that the task can be actioned by the service account and not the end user?

This may be overkill for your particular situation, but yes - such a thing you are looking for is possible if you use the K2 API. We've created Web Services that consume the K2 API to take exactly the action you are trying to accomplish... does your solution currently integrate with any web services or custom code in some other fashion? If so, I can show you how to code this. If not, then we have to look if any of the out of box services or SmartObjects can be called to reasign a task administratively. I haven't tried that yet but would be willing to have a look and see if it is possible without custom code.


Thanks for the quick reply. Yes the solution is connecting to web services so I would be open to your api suggestion as well as one that doesn’t have any custom code.

How do you suggest we proceed? Through here? Via email?

If you are already calling a custom web service, then make a new function in there that references the sourcecode.workflow.management and SourceCode.Workflow.Client DLLs (you might also need the SourceCode.HostClientAPI.dll). Take some time to explore the functions available in these APIs - I think you'll want to use Management to get a particular task, and Client to impersonate a user, open that task and act on it or redirect it.


Thanks. Do you have the code already for this that you could share?


Do you know the user that the task is currently assigned to? If so, you can use the SourceCode.Workflow.Client namespace like so (this assumes your web service is running under the context of the K2 service account):

 

using (var cnn = new Connection())

 

{

// Connect to K2

 

cnn.Open(_k2Config.K2ServerName);

cnn.ImpersonateUser(currentTaskUserName);

worklistItem = cnn.OpenWorklistItem(serialNumber, "ASP", false);

worklistItem.Redirect(serviceAccount);

cnn.RevertUser();

worklistItem.Actionso0].Execute();


Reply