Get Worklist item from Server event


Badge +3

Hi

I need to know the number of task items of a user in a server event. I know user's login.

Need i  impersonate ?

Can i use Connection object in a server event ? 

Thanks for your replies 

 
 


13 replies

Badge +9

You can utilize SourceCode.Workflow.Client.  Since you're within the process, it will connect as the K2 service account.  If it isn't already, grant the Service Account "Impersonate Permissions" within K2 Workspace > Workflow Server > Server Rights.  Once you make the connection as the service account you can then do a Connection.Impersonate() and then call the worklist methods.  This topic is covered in more detail, with code sample, within the product documentation (specifically, K2 Developer Reference > Users > Impersonation > Using User Rights Impersonation).

Please be mindful that worklist retrieval can be a very resource intensive operation (depending on lots of things like volumes, dynamic roles...) which could potentially affect workflow execution.

HTH.

Badge +3

Thank you Bob

I tried this code in my server event :

            Connection server = new Connection();

            server.Open("K2Server");

            server.ImpersonateUser(@"domainuserLogin");
            try
            {
                int itemsCount = server.OpenWorklist().TotalCount;
            }
            finally
            {
                server.RevertUser();
            }
 

 When i start a new instance of my process, i obtain this error in K2 Console log :

Error 2025 Error Marshalling SourceCode.Security.UserRoleManager.Runtime.UserRoleManagerServer.FindGroups, DirectorySearcher returned no results

 

Ideas ?? 

Badge +9

Are you sure that the identity under which you are attempting to start the process instance has Start or Admin rights within K2 for that specific process?

 

Also, on an unrelated note, within the server event code, you'll want to make sure you close the connection (server.Close();).

Badge +3

Service account has admin and start rights on this process.

 

The connection is closed after my code sample. Good remarks.

 

Badge +9
How are you attempting to start this process instance (Workspace, ASP.NET, InfoPath...)? 
Badge +3

With the workspace (Instances...Start new instance).

It's a proof of concept so i didn't develop user interface 

Badge +9
And you're logged into Workspace as the K2 Service Account (t will show in the middle of the page header as "Logged in as"?
Badge +3
I checked it. It's OK.
Badge +9
What do you mean by "it's OK"... things are working as expected or you're logged into Workspace as the service account and you are getting this when kicking off the process?
Badge +3

oops sorry.

I'm logged into Workspace as the service account and i always have my problem.

Badge +9
If you haven't done so already, I'd consider opening a support ticket on this one as I think it may require some digging through logs and configurations to determine what is causing that error.  That is not a common one.
Badge +3

Thank for your help Bob.

I will open a support ticket. 

Badge

DirectorySearcher returned no results normally indicate that the user was not found.


 Have a look in your ADUMError.txt file. If it says something like:


GetUser(DomainName$) OR


GetUser(NT AUthorityANONYMOUS LOGON)


 it means it's trying to authenticate as a machine or as an anonymous user. Have a look at your AppPool settings (it it's from a web site) or your kerberos settings.

Reply