Skip to main content
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
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
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?
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
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 😎 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
Yes...

If you have an Activity with 2 Destination Users (A and 😎, 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
Yes, it's perfect...

Thanks
A last thing...

I don't find how to use K2mng in K2Studio code...
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
Ok, the code is executed but doesn't seem to return any value...

Here is the code

.Value = TargetField;


}

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
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...
Shame on me!!! :oops:

It was really simple in fact...

I just used :


string user = K2.ActivityInstanceDestination.User.FQN;


Is it ok?
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
And do you get all 3 users now? Interesting... there goes my theory...

Regards,
Ockert
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