Skip to main content

Hi I am trying to close off any tasks not finished by users when a workflow ends, We have reached the point where the item is opened, but no matter what options we've tried in terms of sequence to open and / or impersonate the user we can't get it to work. If we use a console app with essentially the same code it does correctly close off tasks. So below is the console code: Any ideas on why it works in a console but not in the code in the Server Event?


Connection oConn = new Connection();


oConn.Open("ServerName");


 




 




 



 


WorklistItem master = oConn.OpenWorklistItem("theItemID", "ASP", false);

 



 


string  targettedUser = master.DelegatedUserse0].Name;

master =



null;



oConn.ImpersonateUser(targettedUser);



 



 





 




 



 


WorklistItem oWli = oConn.OpenWorklistItem("theItemID");


oWli.Actionso





"Processed"].Execute();



oConn.RevertUser();


oConn.Close();


oConn.Dispose();



 

Per the K2 best practices guide (http://help.k2.com/en/KB000352.aspx):


Refrain from using the K2 workflow API  in a process, in particular to access the current process
instance. Trying to use the SourceCode.Workflow.Client API on the same process instance from which it
is being invoked can cause some stability issues due to the way the K2 ser ver handles process
execution.


It isn't even recommended to use the K2 workflow API in other processes, but it might work for you.  I don't know your business requirements, but you could potentially execute an asynchronous IPC event in an escalation, pass it in the serial number and then execute the action from the child process.  In this scenario, the IPC cannot be synchronous.


 


Just a suggestion, if you reach a logical step and need to clean up any outstanding Worklist items in the same process, you can just call the GoTo Method in the server event you've mentioned. This will expire any open items and the process will finish executing.


Reply