How to create K2 Roles and use them in Workflow? What are dynamic K2 Roles and its uses?


K2 Roles are similar to groups in Active Directory which are maintained with in K2 Server. These K2 Roles can be used in workflow for assigning tasks. These K2 Roles can be maintained by administrators for enrolling new users or removing the existing users.

K2 Roles can be added with a User or Group from the default security provider (generally Active Directory)

Now let’s see how to create a role and add users or groups or both to it.

1: Creating K2 Role

Step 1: Open K2 Workspace and navigate to Management Console tab and then right click on Roles and select Add New Role


Step 2:  It will open below screen.


Now enter Role Name & Description and Click Add Role Item which will open another pop up where you can search Users and then select them to add it to Role.

To search user you just need to type the user name in the box provided and then click enter or click search button upon which you would see the users matched with string that you provided in search box. Now select the user that you want to add in role and then click OK.

Same way you can also search for a group to add it in role.

Also you have an option to use SmartObject to fetch the users for role by using the SmartObjects tab which right beside Users Tab in above screen. You just have to select the SmartObject then the SmartObject Method and then the Field which gives you the user.

There is a checkbox with name Dynamic about which I’m going to explain it in latter part of this post.

Now click on Save Button to save the role.

2: Using K2 Role in Workflow Client Event

Now in workflow client event we have 2 ways Simple mode & Advanced Mode

Simple Mode:

In destination user’s field just drag and drop the Role you have created from Context Browser/User Browser/Roles and click finish.


Advanced Mode:

Run the client event wizard in advanced mode (Just open the Destination Users wizard click back button and select advanced checkbox to run in it in advanced mode), Now select Plan per destinationAll at once and click Next button


Now in next screen select Specify the number of the slots to be created and enter 1 and below check Resolve all roles and groups to users (by selecting this option K2 will resolve the role into individual users and the task will be created for each user)

Also below there is a checkbox saying Keep roles synchronized if you check this, K2 will automatically synchronize the role when users are added and or removed while assigning the tasks


Now just click next you will see Destination Sets Wizard where you see Default. Now click edit and add the role from context browser as shown below and click finish.


Now just deploy and run the workflow to see the tasks getting assigned to users from role.

Now let’s see what dynamic K2 Roles are

Basically in K2, Once a workflow instance is created and task is assigned to some destination users then in case if you want to add a new user as a destination user or to remove user from the destination users of the task that is already created, then it is not possible unless we redirect them manually.

Now to mitigate this situation K2 have introduced K2 Roles with dynamic option. So when we say a K2 role is dynamic then it will create only one task with the role name so that while performing the action then the K2 will dynamically check whether the user performing the action belong to the respective role or not.  So now it doesn’t matter how many users are being getting added/removed from role until the Task Action is being performed.

So we just need to check the check box with name Dynamic while creating a role to make it dynamic. By Default the interval for a role refresh is set to 10 minutes. If you want to modify the interval then in WorkSpace / Management Console/ Workflow Server/ Process you will see Roles, click it and add the role that you are using in the client event and then set the refresh interval and save.


That’s it. This is how we can make use of K2 Roles in our workflows.

Below are some of the links that would give more information on using K2 roles in workflows.[continued].html#tracksearch=keep

Handling multiple destination users dynamically from multiple sources.

Hello Friends,

This post is about handling multiple destination users dynamically from multiple sources.

Multiple Destinations.png

Generally we come across this situation while developing workflows, where based on some business rule or condition we need get the users from multiple sources for assigning tasks, Here I’m going to take similar type of situation as an example and will explain you how we can achieve it.


I have a student Admission Workflow in which there is an Approval Activity called Branch Approval. Now for assigning users to this Branch Approval Activity, I need check the Branch of the student and then get the users based on it. Here in this case of my requirement I have a K2 Role and an Active Directory Group and a Constant Value from where I need to get the destination users based on branch condition.

Requirement is something like below:

If Branch is

CSE then assign the task to users from K2 Role,

ECE then assign task to users from AD group users

Others then assign task to a constant user.

Now to achieve this I’m also making use of K2 inline Functions Join and Split. 

Also you refer this link How to create K2 Roles to see how we create and use K2 Role.

let’s start and see how we can do this.

Below is the workflow screenshot


Step 1: Create a new Data field with name Destination of string type, to hold the users that we fetch dynamically.

Step 2: Draw 3 lines for 3 Data Events as shown above and LineRules should be set based on data field Branch.

Step 3: Now in activity Get CSE Users, Drag a Data event and follow below steps

Step 3.1: In source field Drag JOIN function from FunctionBrowser under Text Category.


Step 3.2: Now in values field, you need to open SmartObject Explorer, navigate to System/Management/SmartObjects category and open UMUser Smartobject and select Name field from its Get Role Users method. Once you select it will ask for RoleName, pass role name and click Next and select Return all results option and click Finish. And in separator type semicolon “;” as shown below and click finish.


Step 3.3: Now in Destination field drag Destination Datafield created in step 1 and final screen should look as below Next Click Finish.



Step 4: Now similar to what we did above follow the same steps for the activity Get ECE Users, only difference would be the SmartObject that we are going to get users. As in here my requirement is to get users from AD Group if Branch is ECE, so I’m using below SmartObject to do the same.

SmartObject Name: AD Users

Category: SmartObject Server(s)/SmartObject Server/Active Directory/

Method Name: GetUserByGroup

5. ADSMO.jpg

Once you are done then the screen should like below and click finish.

6. ADFinal.jpg

Step 5: Now moving to activity Get Default Users as per our requirement if branch is OTHERS then assign to some default User so in data event source field I have hardcoded a username and assigned it to data field Destination. Screen should look as below.


I suggest you to get this constant value from some Database or some configuration setting so that it would be easy for use to change or modify this value without redeploying the workflow

Also you can assign to multiple default users by passing them as a semicolon separated string like Domain\\User1; Domain\\User2;

Step 6: Now drag a Client Event give it a name and in Destination Rule option drag SPLIT function from Function Browser under Text category.

8. Split

Now drag the Destination Data field in text field and in separator type Semicolon “;” as shown below.


Now final screen should like below


Now click Finish, configure Actions and then complete and deploy the workflow.

That’s it!! Now test the workflow to see different cases and destination users picked from different sources as per the branch.

This is how we can handle multiple destination users from multiple users dynamically.

K2 Process scheduler

K2 Schedules feature allow to create or edit Jobs which will start a workflow on a particular time in future.

Example :
Once in a week, after every 1 Minute/Hour/Day/Week/Month/Year etc.
To Setup a workflow Schedule follow the below steps.

Step1: Access Workflow Management Site.

Step2: On L.H.S. Menu click on WorkflowServer and then click on Schedules

It will navigate to you Schedules Page

2Step3: Click on new button to add schedule for running the workflow.

  1. Once you click on new button, it will prompt pop. Add the schedule details  like Name, Description and status  details  in this popup.
  2. Under workflow Add workflow Full name
  3. Under “Workflow details” add details like folio and data field required to run the workflow
    Folio can be either Date Time or a Text
  4. Select Recurrence patterns for workflow instance to create. If there is any setting required for selected patterns it will show the…

View original post 147 more words

Exploring the concept of Smart Object References in Workflows.

Let me explain you an interesting concept of adding smart object as a reference to workflow and the benefits of doing it.

Let us assume there is a SmartObject which gets you all the details of students like Roll Number, Name, Branch, Address and Percentage.

Now we need to build a workflow where we need to use multiple properties of students smart object at multiple activities, in a traditional approach we do call the smart object every time in the activity whenever we need. But here, using the concept of references we just have to add a reference to that smart object once and can use its properties anywhere in workflow multiple times.

By doing this way we are optimizing the process design as the calls to Smart Object server will drastically decrease and it will improve the performance of the workflow.

Students Admissions Workflow

Let us see an example with sample workflow for a student admission approval, where at each level/activities we need a student address, marks or percentage and other details.

Now let’s see how we add a reference of that Students Smart object to this workflow.


Step 1:

Navigate to K2 Object Browser, Process/Activity Data Tab and right click on References and Click Add.

Step 2:

Provide some Name and Description to your reference and select the smart object method that gets you the student details. as below Screenshot.


Step 3:

Provide the input parameter, here I’m passing the Roll Number Data field as an input parameter to the Smart Object’s Roll Number property so that for an process instance it holds reference of a single student details.


Finally the Click finish and you should see your reference added in K2 Object Browser as shown below.


That’s it. Your reference to Student’s Smart Object has been added. Pretty Simple but Interesting and Useful feature right!! Now you just have to drag and drop these properties where ever you need in the workflow.

This is how we can add and make use of these references in Workflow designing and improve the performance.


Integrating K2 with Atlassain HipChat

Inspired from my Boss’s (Simon Allport)’s post Slack & K2 Integration I have tried integrating K2 with HipChat and have created a small sample POC for you to look at.

Just to introduce you HipChat, which is an Atlassian Product used for team messaging and Collaboration. For more information you can visit About HipChat.

And to explain about this Sample POC, I have created a sample LeaveApproval Process which will assign the approval task to some User and will send Task Notification in HipChat to that User.

To achieve this we need a HipChat account which we can create here SignUp.

Once the account has been created, login with those Credentials. After you login you need to click on Launch the web app button which would navigate to the page where you can create a room.

Create a room using the link (Create a room) and give it a name, here I have named it as Leave Approval Tasks, and I have added all the approvers (Use Invite Your team) who gets assigned with Leave Approval Requests. So whenever an approval task gets assigned to someone, K2 would send a Task Notification to this room. To make this happen we need create an integration to this room, to do this we need select the room on left panel and click on +Add integrations.


Now Select your room in the dropdown above and give your integration a name in the textbox below (Here I named it as Leave Approval Task) and click Create Button


Once you create an integration you will be redirected to a page as shown below where you would see a URL which you can use to Send Notifications to this particular room. Along with the Url you will see a authentication token which we need to use while sending notifications to this room.

Also at the bottom of the page you see a section Extend HipChat with your Commands, we would talk about this section later in this post as it would be a very useful feature that we can use.


Now our HipChat room is ready to receive notifications. Please make a note of Authentication token and room id from the URL as we are going to use them in code.

Alternatively we can generate authentication token for sending notification using the token generation page as shown below. This generated token can be used in API code.


Let us create an assembly which sends notification to the room which we have created above, this assembly uses HipChat API. So we need to add a reference to it.

For Installing HipChat API run below command in Nuget Package Manager Console. As HipChat API is built on ServiceStack.text 4.0.56 version we need to add the reference of that specific version too, else the code doesn’t work. So execute below commands for adding their references

Install-Package Hipchat-CS
Install-Package ServiceStack.Text -Version 4.0.56

Now add a method as shown below which takes few parameters and creates an HTML Text to send as a notification.

using System;
using HipchatApiV2;
using HipchatApiV2.Enums;

namespace POC.HipChat
 public class SendMessage
 public static string SendHipChatNotification(string UserName, string RequestID, string Originator, string SubmittedDate)

//Room Id – You can get from the integration 
 int RoomID = 0123456;
 //Auth Token which you see while creating Integration
 string Auth_Token = "xx**xxc**xxnhfM***WWE0K***IjEsy***ve";
 string htmlMessage, returnMessage;
 //Form the HTML of Notification with param values
htmlMessage = "<table border='1' style='border-style: solid; border-width: thin; width: 50%; background-color: greenyellow'><tr><td style='width: 7%'>" +
"<img src='link' height='40px' width='50px' /></td>" +
"<td style='width: 90%'>" +
 "<span id='spnMessage' style='font-family: Calibri'>Hey " + UserName + "!! A Leave Approval Request With Request ID : <b>" +
 RequestID + "</b> has been Submitted by <b>" + Originator + "</b> on <b>" + SubmittedDate + "</b> and is pending for your Approval. Please Act upon!!</span>" +

 var client = new HipchatClient(Auth_Token);
 client.SendNotification(RoomID, htmlMessage, RoomColors.Green, false, HipchatMessageFormat.Html);
 returnMessage = "Success";
 catch (Exception ex)
 returnMessage = "Failed " + ex.Message; 
 return returnMessage;


**once the assembly POC.HipChat is built copy the assembly along with HipchatApiV2 & ServiceStack.Text assemblies to C:ProgramFiles/K2BlackPearl/Bin folder

 Now Create an Endpoint Assembly Service Instance as shown below. Here I have named it as POC.HipChat


Once the service instance has been created, you should be able to see the DLL method as shown below.


Now create an SMO for the method using this service instance. Here I have named it as POC.HipChat.SMO


Now our SMO is ready to send Task Notifications to HipChat. Now it’s just calling this method when required to send task notification.

I have created a sample Leave Approval Process which assigns a task to user and sends the notification to room when it assigns the task, also a SmartForm to submit the Leave Request.


Submit Form


I have submitted few requests as you can see in process overview as below


Now let’s see how K2 workflow have sent Leave Approval Task notifications to room with the details in the below screen shot.

Here you see the notifications in HipChat Web Browser


And here as we can see it in HipChat Mobile Notification


This is how we can make use of HipChat to receive K2 Notifications.

Now we can extend this POC to send Task Notification along with actions Approve & Reject Links so that the user can perform the action directly from HipChat itself.

Also in HipChat we have a feature to Extend HipChat with our own Commands, which they call as slash ‘/’ Commands. These slash commands can be used to send requests and get a response back from any server.

Now using these /Commands we can create some custom commands to gettasklist, taskcount, or perform any operation based on our requirements, some thing like below

  • /TaskList                                             –             To Get all active Task List
  • /TaskList {UserName}                      –             To get the Task List of that particular user
  • /ActionTask {SN},{ActionName}    –             To Perform a task based on SN.

This is how we can make use of HipChat and its features to integrate with K2.

Workflow For loop V/s Destination Rule – Plan per Slot (No Destinations)

[Agenda: To check performance variation between Workflow For loop and Destination RulePlan per Slot (No Destinations) with dynamic slot count.]

Working Example: Let me explain through a scenario where we have list of items which we get from an Smart Object method. Now in workflow we need to loop through each item and perform some task.

Now we have 2 ways to achieve this in workflow.

  1. Using ForEach loop
  2. Using Destination Rule (Plan Per Slot (no Destinations))

Our motive here is to find out which one is faster in execution.

Let’s see the workflow below and go through the each activities.


010-oneIn this step, “Add to audit” is a SmartObject Event which will insert a record into SQL data base. Here I’m using it to record time stamps to SQL db.
In this particular activity I’m logging this text “For Loop Beginning – {Date Time Stamp}


In this step, Add For each Event, and click on the icon beside source text box and selected the Smart Object Method that will return us list of Items.


008-threeIn this step, log each item to database. You will need to get the value from Item References under Process/Activity Data tab in Context Browser. See below screen shot.




In this step, Log this text “For Loop End & Dynamic Start – {Date Time Stamp}


 006-fiveIn this step, Add an activity and select destination rule Plan per slot (no Destinations).

(***If you are unable to see this option then just click back button and check advanced option and click next)

Click next button, now you need to select second radio option which says “select a list field to determine how many slots should be created.”

Select the Smart Object method which gives you the list of items and finish.

Now you can access those items in Instance Data Field under tab Activity Destination Instance in Workflow Context Browser.

See below screens PlanPerSlotLogDynamicItem



In this step, log text “Dynamic End – {Date Time Stamp}


Now just deploy the workflow and start a process instance and check the data base results. 




Result: For loop took 5 seconds to log 10 items to data base whereas Destination Rule took just 1 second to log 10 items.

So conclusion here is Destination Rule method is much faster than for loop.

IPC Thread Pool Settings

Have you ever wondered why in IPC Events when you are triggering a child workflow it takes some time to initiate and also in case of Synchronous calls it takes time to receive the call back from child work flow?

The reason for this is, K2 have provided a small configuration setting (See Below) in K2Server.Setup File which will be available under path C:\Program Files (x86)\K2 blackpearl\Host Server\Bin

<IPCSettings ExpireOnDelete=”false” IPCThreadInterval=”60″ />

Default value is set as 60 sec, which means for every 60 sec the IPC thread will check for new IPC Calls and trigger them.

You can decrease this value to speed up the IPC calls. But K2 have suggested not to set the value below 5 seconds due to some performance issues.



There are few more settings that could be helpful for us to know. Please find below article which explains more useful settings.