How to get total # of destination users programmatically


Badge +3
I'm looking for a way to find out how many destination users exist for an activity programmatically.

When I do:
K2.Destinations.Count
I typically get 1, because I am using just one Destination Queue. But what I really want is the number of destination users for this activity.

Can someone help me out with a way to get the count of the users and/or get the users from K2.Destinations ??

It would be so helpful if there is a straightforward way.

2 replies

Badge +9
Firstly you need to understand the lifecycle of an activity.

Activity Lifecycle during runtime:
1. Preceding Rule
2. Start Rule
3. Destination Rule
4. [Events contained by the Activity]
5. Succeeding Rule

The actual count of destinations can be programmatically determined in the following stages of the Activity:
1. Any event contained by the Activity
2. Succeeding Rule
3. Lines (Exit lines only)

The specific code required to retrieve the count is determined by the context of the stage you are working in, see samples below:

Client Event:
K2.ActivityInstanceDestination.ActivityInstance.Destinations.Count


Server Event:
K2.ActivityInstanceDestination.ActivityInstance.Destinations.Count


Succeeding Rule:
K2.ActivityInstance.Destinations.Count


Line Rule:
K2.LineInstance.StartActivityInstance.Destinations.count


The image below illustrates the use of Console.Writeline to test the various stages of an activity. (Tip: Run K2.net Server in Console Mode)
1. Preceding Rule
2. Start Rule
3. Destination Rule
4. Client Event
5. Server Event
6. Line Rule
Badge +3
Thank you for this extremely detailed explanation.

Actually when I do destination.count i just get the result 1, for the destination queue (which is a group - I'm still using SP1). So I ended up using this example from another posting:

ADUM.K2UserManager ADUMMgr = new ADUM.K2UserManager();
SourceCode.K2UMI.IK2Users Users;
Users = ADUMMgr.FindSecurityUsers(adGroup , null, null, null, null );
if (!(Users == null))
{
foreach (SourceCode.K2UMI.IK2User User in Users)
{
count++;
//Console.WriteLine("Destinaton User is: " + User.Name.ToString());
}
}

This way I just get actual number of users. I actually need to get the number of users/destinations before the client event finishes (before the succeeding rule is evaluated).

But thank you for the explanation. It actually helps clarify a few things.

Reply