Delete a users tasks via the api

  • 24 February 2010
  • 6 replies
  • 12 views

Badge +2

 


Can anybody dig out some sample code that shows how to delete tasks for a specific user via the api for a specific process?


I have the requirement for the ability to remove users from a workflow after they have had tasks assigned to them.


Ithanks


jon


6 replies

Badge +4

Hi Jon,


 


Once the task is allocated to the user you can't remove it from just that user with the API.


I have a few ideas but would like to know more about how you currently setup your destinations.


Ashley

Badge +2

 


Hi Ashley the Reviewbyreviewers task is the task that i would like to be "removed" from the destination user.


Please see the attached project and for details I am picking up on this work after having a k2 consultant do the initial development for me.


One idea i might try is redirecting the task to another user via the k2 workspace.


This is a bit clunky though as Im not sure if my users will get workspace access.


Many thanks for your help and expect a lot more dumb questions i'm afraid!

Badge +4

Hi Jon,


I have no quick solution here.  If you can make somethig work with redirections then go for it.  Another idea would be to expire the activity for all users and then recreate the task after recalculating the destination users xml list - this would resend out emails to destination users etc.



How do you want this removal of users to be triggered?

Badge +2

Hi Ashley,


 


The redirection idea worked fine.


One thing I would like to investigate is whether it would be possible to programmatically retrieve an action from a users worklistitem and then execute it this would then remove it from a worklist.


goto methods could be invesigated too perhaps?


thanks


jon

Badge +4

Hi Jon,


 


It would be posible to programatically get the worklistitem object and complete the task on behalf of the user.  There are a cople of ways to do this.


If you can get hold of the serial number for the user's task then you could use the workflow client api to open and complete the task


using SourceCode.Workflow.Client


Connection c = new Connection();


c.Open(wfSerevr)


c.Impersonate(userTaskIsAllocatedTo)


c.OpenWorklistItem(serialNumber).Actions["Complete"].Execute();


In essence you need to get a handle on the WorkListItem object and execute the action against it.  If you can't think of a way to get the serial nuber you could also try using c.GetWorklist() this accepts a FilterCriteria object that you could potentially use to filter your user's tasklist for the specific worklist item you want.


The user account that executes a c.Impersonate() call must have Impersonate permissions in the Management Console/Workflow Server/Server Rights list.


GoTos are another option - the main point to bear in mind there would be that they expire all current activities - this is only really an issue if there are parallel activites running in the workflow.


 


 

Badge +2

nice one ashley,


This is all very informative thanks for your help!

Reply