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.
+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:
Server Event:
Succeeding Rule:
Line Rule:
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
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
+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.
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
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.