Find the user who effectively open the activity (Resolved)

  • 16 December 2005
  • 15 replies
  • 6 views

Badge +7
Hi,

I will need to know how to find programmaticaly the user who get the activity assigned to him.

i.e. if there are 4 people for 1 slot, how can I know who opened the activity?

Thanks

SOLUTION:

To get the user who has effectively opened an activity, in case where there is many users in Destination for one slot, use this code in a Data manipulation event after all other events in the activity:


K2.ActivityInstanceDestination.User.Name

15 replies

Badge +11
You'll have to use K2Mng. Retrieve a collection of all the worklist items with a specific folio or process instance ID and look for the one with Status = 'Open'.

Obviously, the user making the call to K2Mng will need to be a K2.net Server Administrator.

Regards,
Ockert
Badge +7
If I put this action (retrieve user) in server event, it will use K2Server credentials. Is it enough to use K2mgr?

Does this code return return the user ?


K2.ActivityInstanceDestination.User


To finish, is it possible to record an object (for example, the user object) in a variable in order to reuse it later?
Badge +11
It depends on whether or not the user account running K2.net Server has got Administration rights in K2.net Service Manager.

Yes, that code does return the user but ONLY of the current ActivityInstaceDestination of course.

Yes, you can store the result of the K2Mng call to WorklistItem.DestinationUser into a variable and reuse it later.

Hope I've answered your questions,
Ockert
Badge +7
Almost...

It is because English is not my native language so I'm not sure to understand exactly...

for the current ActivityInstaceDestination, if I well understood :

If I have 2 destination user (A and B) with one slot; if A open the activity,
the K2.ActivityInstanceDestination.User will give me user A, true?

For reuse the user, can I store it in a process data field to reuse it in another activity? if yes, which type of data must be the field ?

Thank you very much
Badge +11
Yes...

If you have an Activity with 2 Destination Users (A and B), one Activity Instance and 2 ActivityInstanceDestination objects will be created i.e.

* ActivityInstance
* ActivityInstanceDestination (for User A)
* EventInstance (Server Event)
* EventInstance (Client Event)
* ...
* ActivityInstanceDestination (for User B)
* EventInstance (Server Event)
* EventInstance (Client Event)
* ...

So, each ActivityInstanceDestination will have a different 'User' property. The Server Event in both ActivityInstanceDestination objects will fire and a worklist item will be created for each user (ActivityInstanceDestination).
When user A opens AND completes the worklist item, user B's worklist item will be expired (if only 1 slot were specified).


A string - pocess level datafield should do just fine.

Hope this makes sense,
Ockert
Badge +7
Yes, it's perfect...

Thanks
Badge +7
A last thing...

I don't find how to use K2mng in K2Studio code...
Badge +11
Add a reference to the K2Mng.dll file in your K2.net Studio process and use code similar to code samples in help file. Alternatively, write an external assembly which references the K2Mng object model and call this external assembly from within you process.

Regards,
Ockert
Badge +7
Ok, the code is executed but doesn't seem to return any value...

Here is the code

.Value = TargetField;


}
Badge +11
I would add a couple of 'Console.WriteLine' statements and start K2.net Server in Console mode for debugging purposes.

I'm not too sure that 'if(item.Status.ToString() == "Open")' will evaluate to true since Status is an int where 'Open' = 1.

Any Error Profiles?

Let us know,
Ockert
Badge +7
Ok, I continued to search, and the problem was apparently the use of 'K2.ProcessInstance.Process.Name' but no matter... I put null for process name and it's almost OK.

I have now a new trouble... It seems that the method GetWorklistItems() return only non-opened items... I explicit this now:

I have an activity with two events (1 smart Form and 1 Data manipulation).

For this activty I have 3 users as Destination with one slot.

When a user fill the form, the data manipulation gets only 2 worklist item and the Destination for these two items are the two other destination users.

To resume, GetWorklistItems() method never get the activity opened by the user...


I continue to search for another way to get it but if you have some advice...
Badge +7
Shame on me!!! :oops:

It was really simple in fact...

I just used :


string user = K2.ActivityInstanceDestination.User.FQN;


Is it ok?
Badge +11
It is probably because the Data Manipulation event occurs after the Client event (SmartForm). When UserA submits/completes his/her worklist item, it is removed from the corresponding tables and the process continues to the next event. At this stage the other 2 worklist items has not been expired yet and will still be present (although not accessible through K2ROM).

I'm not sure what your exact requirement is but you should probably move your Data Manipulation code to the Smartform - if you want to pick up all three users.

Regards,
Ockert
Badge +11
And do you get all 3 users now? Interesting... there goes my theory...

Regards,
Ockert
Badge +7
Yes, your theory seems exact...

But if I put Data manipulation before client form, there is no worklist (it is logical), that's why data manipulation was the second event.

I will put it on the first post to avoid people to look through all this messages

Reply