Thursday, July 23, 2009

K2 Roles

Introduction to K2 Roles

K2 Roles are a way to create re-usable groups of users that can be used across processes. For instance you could create a K2 Role called Accounting Managers and that K2 Role can be used in a K2 Destination Rule. They are similar to an AD Group or a SharePoint Group but a little different. One added advantage of using K2 Roles will be kept in sync with tasks created for users to action. So what does that mean? Basically when you do not use a K2 Role and assign a specific user account to a destination rule that account will tied to the slot that is created at run time. Once the slot is created for that destination user it cannot be changed unless the user or administrator delegates the task. However if the you use a K2 Role, users that are in of the Accounting Managers K2 Role, will have immediate access to the worklist item slot (based on the refresh interval). So this is good thing to use if you anticipate that users who can potentially be assigned a task may change often.

I highly recommend reading this whitepaper - It explains what is a K2 Role in detail.

Here are some of my notes on K2 Roles:

  • Destination Rules are required to compile a client side event. They can be set to Static user: user dynamically, AD Group, XML list, K2 Role, SmartObject, etc.
  • K2 Roles are a role is a common group that is defined within K2 that can be re-used across K2 processes. K2 Roles can be made of from accounts in AD or a custom repository like in SmartObject.
  • Slots determine how many Worklist items can be Open for an Activity. As soon as a user clicks on a Worklist item, the status immediately changes from Available to Open and 1 Activity Slot is occupied. The number of Slots can be limited to a specific number or a slot can be created for each destination. Slots control how users will work with data. Configuration of the destination rules directly determine how many slots are created.
  • Succeeding rules by default will evaluate the outcomes of actions along with the Slots that are created to determine if the Activity is allowed to go to the next Activity in the process.
  • By default all destination rules are set to "plan just once". A slot will be created for each user and a Worklist items is created however only one activity instance is created. Any time a user is added to a K2 Role it should appear on their worklist based on interval.
  • Plan per Destination supports parallel processing as multiple activity instances will be created for each user. "All at once" allows all users to access the worklist item. One at a time" only allows one user at a time to access the item.
  • Plan per Slot use for an IPC event or call out to an external system.
  • Cached K2 Roles - By default, a single slot will be created for each Role. By default, on a 10 minute interval, the Role and its users will be refreshed with that slot. This can be configured in each K2 process that is deployed by using the K2 Workspace. If you select, "Resolve all roles and groups to users", changes to the K2 role will not be reflected but using the "Keep roles synchronized" checkbox will keep in sync on interval.
  • Dynamic Roles can only be used with "Plan just once" or "Plan per destination" where Roles do not resolve to users. Dynamic roles are on-demand. This means the K2 Role is refreshed when dynamic roles are defined and every time worklists are opened which contain items that use the role. This ensures that new users in a K2 Role will see the worklist item immediately and users removed from K2 Role will have permission blocked.

Getting User who Actioned

When using K2 Roles I have run into situations that have tripped me up a couple times. Let's say I have a client side event (InfoPath) and I want to perform custom code after the InfoPath event. Specifically, I need to know who was the user who actioned the event. To do this you need to execute the following code:

public static string GetActionUser(ActivityInstance activityInstance) {
//Loop over the activity slots to see who was the user who
//actioned the worklist item.
foreach (Slot slot in K2.ActivityInstanceDestionation.ActivityInstance.WorklistSlots) {
if (slot.Status == ActInstSlotStatus.Completed) {
return slot.User.Name;
return "";

What this does is loop over the slots, checks which slot was completed and by whom. You cannot go directly to the ActivityInstanceDestionation because the K2 Role was assigned as the destination user. However slots will be created dynamically for each user in the K2 Role based on the refresh interval.

Email All users in K2 Role

In many situations, I have needed to email all of the users in a K2 Role. One solution to do this without having to write any custom code would be to go to the advanced destination rules of an activity where an Email Event has been added. Select Plan per Destination All at Once. Then select Resolve All Roles to users. Then in the Email Event select send the email to the Destination User checkbox. I would only recommend doing this in an Email Event that is in its own Activity. Do not do this in the same activity where you have a client side event, like an InfoPath event. What this will do is not allow the K2 Role to be dynamic refreshed defeating the purpose of all the stuff we just talked about.

Another approach would be to use the following code to build a string of email addresses that are in the K2 Role. Then set the email string into an activity level field. Then use activity level field in the Email Event wizard. You can see in the code I have an AD SmartObject with a method called GetDetails that I use to get the user's email address.

using SourceCode.Security.UserRoleManager.Management;
using SourceCode.SmartObjects.Client;
public static string GetEmailsInRole(string conn, string roleName){
string emailAddress = "";
conn = conn.Replace(" ", "");
UserRoleManager roleManager = null;
SmartObjectClientServer server = null;

try {
//Create Manager
roleManager = new UserRoleManager();

//Get Role
Role role = roleManager.GetRole(roleName);

//SmartObject server reference
server = new SmartObjectClientServer();

//Get Person Definition
SmartObject person = server.GetSmartObject("Person");
person.MethodToExecute = "GetDetails";

foreach (RoleItem item in role.Include) {
//Now get the email from the smartobject
person.Properties["ADID"].Value = item.Name.Replace("K2:", "");

emailAddress += person.Properties["Email"].Value +";";

//remove last semi-colon
emailAddress = emailAddress.Substring(0, emailAddress.Length - 1);
catch (Exception ex) {
Finally {
if (roleManager.Connection != null) {

if (server.Connection != null) {

return emailAddress;

Wednesday, July 1, 2009

K2 Process Deployment Dependencies

There have been some recent questions to me about K2 process deployment dependencies. I wrote the chapter in the book which focused really on how to deploy a K2 process or SmartObject from one environment to another. It discussed the relationship between environments and the StringTable, MSBuild and deployment dependencies you need to consider. However there are some elements to a K2 process deployment that you still must consider which can be taken for granted.

Remember that most everything you configure in the K2 Workspace must be re-configured in your destination environment. Let me clarify this:

  • K2 Roles – Roles within K2 are created on the K2 Workspace, they are not defined as part of the K2 process. The K2 process will reference them; and if they are not there, you will get a deployment error when deploying from one environment to another. There is a K2 blackmarket projects that can help with this - and
  • Environments – This is a tricky one to explain and recommend that you read the book. When doing a process K2 process, values in the destination Environment will set into the StringTable. So the K2 Development server will have values in the Environments and when a process is deployed to a K2 Production server the StringTable will be populated. However the K2 Production Server will not have values populated its Environment Settings in the K2 Workspace. Environment Settings are unique to the server. This can be a challenge if developers have localized development environments and they need to share kprx files. The developer will need to create the Environment settings for their localized environment.
  • Working Hours – Will again need to be reconfigured in each environment manually as they are not part of the process definition; they are just referenced.
  • Permission (Server and Process) – It is obvious that K2 server permissions will need to be reconfigured on each server. However remember that the Process permissions will again need to be re-configured on each sever the process is deployed to. It is not part of the process definition.
  • Error Profiles – Those will need to be reconfigured on each K2 server. You may be creating profiles by process definition.
  • SmartObject Services – This is discussed in the book but worth mentioning again. SmartObject Services like the SmartBox and AD are deployed in every K2 server as part of the install. However other custom SmartObject services are not and this can cause a wrinkle in your deployment. In the K2 book, there is a section devoted to GUID in a SmartObject (Pages 323 to 325). This is a must read. Here are some K2 blackmarket projects to help with this - and

You still also need to consider all other applications and components that must be deployed before you deploy your K2 process. For instance:

  • SQL Databases
  • Web Services
  • SharePoint Lists, Document Libraries, Form Libraries
  • Content Types
  • Custom Site Templates
  • Custom SharePoint Features
  • Custom Web Parts
  • pages
  • SharePoint Sites and Pages
  • Etc.

The list can go on. So when doing a deployment, you really need to map out all dependencies of the entire solution and ensure that you deploy everything in the right order.

K2 User Group July 2009

There will be a cool User Group this month on K2 and doing custom reporting with SSRS and PerformancePoint – looking forward to it.


Hello Everyone,

Phillip Knight from Merit Energy will be hosting the K2 user group meetings at Merit Energy, located at 13727 Noel Road, 2nd Floor Conference room, Tower 2, Dallas, Texas 75240. Parking information is included in the linked map below. Remote attendance information is included at the bottom of this message.

Link to map: Reminder: Merit Energy is on the 5th floor, but the meeting will be held in a 2nd floor conference room. Once off the elevator, go to the reception area and we will bring you back to the conference room.

Please RSVP to me via email
whether you are attending via live meeting or if you will be attending in person (so that we can plan for the number of people to order food for).

Check out the K2 Underground site and our user group at We are posting webexes/live meetings from our meetings at this site.

08/11/2009 11am – 1pm
09/8/2009 11am – 1pm
10/13/2009 11am – 1pm
11/10/2009 11am – 1pm
12/8/2009 11am – 1pm

Meeting Agenda:
11-11:15 Networking/Refreshments
11:15-11:30 Announcements/Intros of New people
11:30-11:45 Tips & Tricks
11:45-12:45 Technical Presentation
12:45-1:00 Meeting Wrapup

The Announcements section of the meeting will include any information regarding K2 upcoming events and user group events as well as brief introductions of our presenter and refreshment provider.

The Tips & Tricks Presentation is when we as members can pose questions to each other on projects that we are working on and having difficulty with. It is also a time when if we have learned something that we feel will be helpful to others, we can share it with the group. Bring yours to share/ask.

Meeting Presentation & Company & Sponsor:

Jonathan King will be presenting an array of ideas on how to approach custom reporting in both K2 blackpearl and K2 blackpoint. He will be demonstrating a number of custom reports developed using SSRS upon both standard K2 process information and SmartObject information as well as how to develop Process Maps in Microsoft PerformancePoint.

K2 blackpoint, a subset of K2 blackpearl features, provides unparalleled capabilities and affordability. It also offers an upgrade path so that organizations can grow their investment and add complexity over time, if needed.

For more information, go to

The K2 platform is for delivering process-driven applications that improve business efficiency. Visual tools make it easy for anyone to assemble reusable objects into applications that use workflow and line-of-business information.

K2-based solutions are deployed by a growing number of the global Fortune 100. K2 is a division of SourceCode Technology Holdings, Inc. based in Redmond, Washington, and has offices all over the world.

For more information, contact Joe Bocardo at

Meeting Presenter:

Jonathan King is the K2 Technical Specialist for Europe and is responsible for promoting the K2 suite of products with prospects, customer, partners and the broader K2 community. Jonathan has been working with K2 products for the past five years the last three of which have been directly for K2 out of their European head office in London. Jonathan is available at

For Virtual Attendees:

Note: please keep your phone on mute until you are ready to speak.

Audio Information

Telephone conferencing
Choose one of the following:

Start Live Meeting client, and then in Voice & Video pane under Join Audio options, click Call Me. The conferencing service will call you at the number you specify. (Recommended)

Use the information below to connect:
Toll: +1 (719) 867-1571

Toll-free: +1 (877) 860-3058

Participant code: 914421

First Time Users:

To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Unable to join the meeting? Follow these steps:

Copy this address and paste it into your web browser:

1. Copy this address and paste it into your web browser:

2. Or Copy and paste the required information:


Meeting ID: KRQ226

Entry Code: NO Entry code for attendees

If you would like to provide refreshments at an upcoming meeting or present at an upcoming meeting, please contact me.

Let me know if you have any questions prior to the meeting.

The next meeting announcement will be sent out next Tuesday.


Have a great day!

Patti Albracht