Building a Workflow with K2 Five

This ‘How To’ goes through the steps of building a simple workflow using the new workflow designer in K2 Five.

K2 Five is a complete redesign of the web based workflow designer and it also forces the developers to rethink how they develop their workflows.  The new designer is not just aimed at citizen developers like the previous version of the web based designer found in K2 Blackpearl, but  now at  professional developers as well.

K2 Five Workflow designer has all the power of K2 Studio, but with the benefit of being all web based, so there is no need to install client tools on a developers PC or having to install Silverlight plugin  on a compatible browser as it is all now HTML 5.


Case Study

GreenEggs Studio needs a simple annual leave request solution to replace their existing paper based system. They have decided to use K2 to build the solution because of it’s rapid development and low / no code proposition. As it is their first application in K2 they are going to keep the process small and simple.  They also want it to get the leave request out into the business as quick as possible so they are taking an agile MVP approach so they can iterate or add features based on user feedback instead of assumptions.

The process map looks like this

Leave Request

As you can see it’s a very simple process.

  1. An employee fills out and submits the annual leave form.
  2. Their line manager receives an email asking them to review the request
  3. If the line manager declines the request, the employee receives an email saying it has been declined and the status is updated
  4. If the line manager approves it, the employee receives an email saying it has been approved and the status is updated


Getting Started

Simple workflow

So lets get started with designing a workflow with K2 Five.  We are going to build a simple workflow to create annual leave requests.  The Smartforms and SmartObjects have already been built.

  1. Go to the K2 Five DesignerDashboard
  2. Click on ‘Workflow’
  3. The workflow design wizard will load up and ask to enter in a name and the location of where you want the workflow to be saved to.workflowwizard
  4. Lets give the workflow a name like ‘HR.WKF.AnnualLeave’, the way I have named the workflow  is that so we can identify what solution the workflow belongs to. In this case the ‘HR’ solution.workflowname
  5. Now lets choose the location, click on the blue ‘workflow’ link underneath the workflow name. A window will popup showing a list of folders.
  6. Select the ‘HR’ folder’ and click on ‘Ok’. If there is not a folder there already then click on ‘Create Folder’ and enter in the name ‘HR’.folder
  7. On ‘Ok’, the folder window will close and the folder location under the name will say ‘HR’folderchange
  8. Now click on ‘Create’ button, this will now take us into the new design canvas.create
  9. When the canvas loads up, we are presented with a smart assist helper to give us a brief introduction into the new workflow designer. You can click on the left and right arrows to view the helpful clips and then click on close after you have finished.welcome
  10. Welcome to the new K2 Five workflow Designer 🙂 welcome1
  11. The Smart Assist is always present within the new designer and when you are new to the designer it will suggest what to do next. You can either just click ‘x’ and it will close the smart assist for this workflow or you can click ‘Got It’ and it will assume you know what you are doing. In this case I am going to just going to click on ‘x’ to close it.
  12. Once the smart assist is closed the first thing you will notice is now simple the designer now looks.  There are a couple of things that are very different if you have used K2’s previous workflow designers both web and studio.  Activities, steps and events are gone and now replaced with ‘Shapes’ So throughout the rest of this guide you will notice I will be using  term ‘Shape’ instead of event. So for example ‘I am going to drag the ’email shape’ onto the canvas instead of the email event’
  13. So on the canvas we start with the ‘Start shape’ and you can see it has put a maker where we can place the next shape.start
  14. So now that we have a canvas to build the annual leave process on. On the lefthand side of the canvas we have a toolbox of all the shapes that the workflow can carry out like creating a task, sending an email etc..  To view the shapes click on ‘>’ to expand the toolbox.
    Click to expand

    Expanded Toolbox
  15. The first shape we are going to drag onto the canvas is a Task. Drag the task shape taskicon into the placeholder on the canvas. The canvas should look like the image below. A ‘!’ explanation mark will be displayed against the task shape, don’t worry about that, K2 is just letting us know it’s not yet configured.taskcanvas
  16. Now Click on the Task shape on the canvas and now the righthand side configuration panel icons will change to show the task configurable options.
  17. Click on ‘<‘ on the configuration panel to expand the options.taskconfig1
  18. The first tab in the task configuration options is where we can give some instructions to the person(s) receiving the task about what the task is about. It is also where we can say what actions the person(s) interacting with the task can perform.
  19. So lets add some basic instructions “Please review the details of the leave request and either  click on ‘Approve’ or ‘Decline’instructions
  20. Next we are going to add the actions for the task. For the standard actions like ‘Approve and ‘Reject’, K2 have made it easy for us by giving us them the default options which we can just click on to create the actions.defaultactions
  21.   So lets just click on ‘Both’, the actions will appear and K2 Smart Assist will appear showing how to create action paths. Click on ‘x’ close to close the Smart Assist.defaultactions1
  22. Now click on the next tab in the configuration options, here we can choose which form will be used for the task.  We can choose from the following types
    1. Basic Task Form, K2 autogenerates a form which is presented to the user to choose a specific action
    2. Smartform, we can select an existing Smartform to use from the library
    3. Custom, we can enter in a custom form by putting in the URL of the form we are going to use.
    4. No form, it is possible to have a task that has no form for the user to go to.
  23. For now we are going to use ‘Basic Task Form’, we will go back later and change it to a specific form.basicform
  24. Next we choose who will receive the task, so we need to click on the next tab to choose the recipient.recipeint
  25. By default the task will goto the person who submits the leave request. So we need to change this to be their line manager. Click on ‘Originator’ and select ‘Originator Manager’ from the list. Now the task when generated will go the manager of the person who submitted the leave request.recipeintLinemANAGER
  26. Looking at the process map, the line manager also needs to receive an email notification to say that they have a leave request to complete. Click on the next tab down with letter icon. Here we can decide if the line manger will get an email notification. We can either use the standard notification email or we click on ‘Customise Notification’ and create a custom notification email which can include actual business data that is relevant to the task. For now we are just going to use the standard notification.NOTIFICATION
  27. For this walkthrough we will leave the other options for another time. We have now configured a basic task for the line manager to receive once a member of their team submits a leave request.
  28. Double click on the word ‘Task’ replace the text with ‘Line Manger Review’linemangerreview
  29. Now to create the decision branches on the workflow, left click and drag from the bottom of the task shape to create a new line and placeholder.linemangerreview.actionsPNG
  30. Now drag the blue diamond shape (decision shape) bluediamond into the placeholder. K2 will then pick up we have two actions from the previous shape and will automatically create the decision outcomes based on those actions.linemangerreview.action1
  31. Now lets deal with the ‘Rejected’ decision branch.
  32. In the process map, when a leave request has been rejected, we need to send an email to the employee who submitted the leave request. In the toolbox on the left hand side drag the email shape emailshape on to the canvas. Your canvas should look the below imagerejectedemail
  33. Now left click on the  orange dot next to ‘Rejected’ and drag it on to email shape we just dragged onto the canvas.rejectedemail1
  34. Now lets configure the email, first of double click on the ‘Send Email’ text and enter in ‘Reject Email’
  35. Click on the email shape again and expand the configuration panel on the righthand side.configurerejectemail
  36. We don’t need to change ‘To’ as it is already set to ‘Originator’ which is the person who submitted the leave request form.
  37. In the Subject enter in the text ‘Leave Request Status’
  38. In the Body section for now just enter the following text ‘Hi, Your Leave request that was submitted to your line manager has been declined.’ We will come back to this later on and enter in some business data that relates to the actual leave request. But for phase 1 we will keep it very simple.configurerejectemail1
  39. Now  lets do the ‘Approved’ decision branch, like with the rejected branch drag another email shape from the toolbox  onto the canvas. approvedemail
  40.  Now drag the orange ‘Approved’ dot approved dot to the email the email shape.approvedemail1
  41. Click on the email shape we just dragged onto the canvas and then expand the email configuration panel on the righthand side of the canvas.approvedemail2
  42. In the Subject enter ‘Leave Request Status’ and in the Body section enter in the following ‘Hi, your line manager has approved your leave request’approvedemail3.PNG
  43. Now click on the next tab in the email configuration panel, here we can change the name of the email shape from ‘Send Email’ to ‘Approve Email’. We can also use this section to enter in additional notes about the email shape.approvedemail4.PNG
  44. In the name section, remove the text ‘Send Email’ and change it to ‘Approve Email’approvedemail5
  45. We have now configured the email for when the leave request has been approved by the line manager. The canvas should now look like the image below.approvedemail6
  46. Now to finish off the workflow we now need to add a ‘End’ shape. In the toolbox of shapes it is the Red Square end. Drag this on to the canvas underneath the other shapes. It should look like the image below.end1
  47. Now we can connect the ‘Approve Email’ and ‘Reject Email’ shapes to the end. Like when connecting the decision branch to the email shape. Just left click and drag from the bottom of the email shape to the end shape. Your canvas should now look like this.end2
  48. Now we have completed a very a simple version of the leave request. The leave request gets submitted. The line manager of user who submitted the leave request then receives an email asking them to approve or reject the leave request. The user who submitted the leave request then will get an email telling them of the decision that was made by their line manager.

Using SmartObjects inside the leave request workflow

  1. The leave request has a SmartObject,
    1. HR.CMN.SMO.LeaveRequest, this holds the leave request details like leave dates, number of days, status, who created it and when.leavesmo
  2. So now lets edit the workflow we created earlier to use the data from the SmartObject HR.CMN.SMO.LeaveRequest. To do this we need to add a variable to hold the LeaveRequest number. This is so the workflow can find the correct leave request details.
  3. Click on ‘Start’ shape and then click on the configuration panel on the righthand side of the canvas. Then click on ‘<+>’ symbol in the top right corner as circled in the image below.datafield
  4. This will expand the ‘Context Browser’ for the canvas. The context browser will show any references, variables and environment fields that are currently being used in the workflow. It also gives you access to workflow details and workflow functions.
  5. As this is the first time we have used the context browser in this workflow. We just a brief description of what references and variables are.  Under Variables click on ‘Add Variable’.datafield1
  6.  A new variable called ‘New Data Field’ is created. Click on the text ‘New Data Field’ and delete the text and replace it with the following text ‘LeaveRequestId’.datafield2datafield3
  7. The next thing we need to do is change the data type of this variable. At the moment it is set to ‘Text’ as we need the variable to store a number click on ‘…’ and click on ‘Settings’.datafield4
  8.  We are now in the settings for the variable, under ‘Data Type’ you will notice it says   ‘Text’.datafield5
  9. Click on the drop down list that says ‘Text’ under ‘Data Type’ and choose ‘Number’ and click on ‘Ok’.datafield6
  10. We have now created and configured a variable to hold the related Leave Request Number. We now need to tell the workflow which data to retrieve. To do this we need to create a short cut to the SmartObject ‘HR.CMN.SMO.LeaveRequest.
  11. Expand the shape toolbar on the lefthand side of the canvas and click on ‘Basic’.REFERENCE
  12. We will now see all the shapes under the ‘Basic’ category.  The shape we want is called ‘Create Reference’.REFERENCE1
  13. Click and drag it on to the canvas. REFERENCE2
  14. Click on the ‘Create Reference’ shape and then expand the configuration panel on the righthand side of the canvas. The first thing you will notice that we have to do is select a SmartObject.createreference
  15. Click on ‘Select SmartObject’, this will bring up a window to select a category where the SmartObject is stored.createreference1
  16. The SmartObject we want is under ‘HR’ – ‘SmartObjects’. Click on ‘HR’ , then click on ‘SmartObjects’ and then select the SmartObject ‘HR.CMN.SMO.LeaveRequest’ and click on ‘OK’.createreference2
  17. Now that we have selected the SmartObject, we now need to select which method the reference will use to get the correct data.  Click on ‘Select Method’ and select ‘Load’.createreference3
  18. Because we have selected the ‘Load’ method, it requires some input data to retrieve the correct row of data. In this case the load method requires that a value is passed in the property named ‘Id’.createreference4
  19. If the ‘Context Browser’ is not expanded click on ‘<+>’ symbol in the top right corner of the panel. We will now see the variable we created earlier, now drag that into the box labeled ‘Type / Drop’ next to the property labelled ‘ID’. It should look like the image below.createreference5
  20. Now that we have configured the reference, to retrieve data where the value of the property ‘ID’ is the same as the value of the variable named ‘LeaveRequestId’. If you  you know SQL we are essentially doing this ‘Select * from HR.CMN.SMO.LeaveRequest where ID = @LeaveRequestId‘.
  21. Click on the next tab in the configuration panel and under ‘Name’ replace the text ‘Create Reference’ with ‘Leave Request Details ‘.createreference7createreference8
  22.  Click on ‘>’ to close the configuration panel’, we have now created a short cut to the leave request data. We now need to link the reference into the workflow so the workflow will retrieve the correct data before the task for the Line Manager is created.
  23. On the canvas, disconnect the line going from the ‘Start’ shape to the ‘Line Manager Review’ shape. As shown in the image below.createreference9
  24. Now drag the reference shape named ‘Leave Request Details’ in between the shapes ‘Start’ and ‘Line Manager Review’. Then connect the line from the ‘Start’ shape to the ‘Leave Request Details’. Then left click and drag a line down from the bottom of the ‘Leave Request Details’ shape to the top pf the ‘Line Manager Review’ shape. Your canvas should now look like the image below.createreference10
  25. Now that the workflow has access to the leave request details that was entered in the submitted leave request form we can now give some context to the emails that are sent out as part of the workflow.
  26. Lets start with the email notification to the line manager of the person who submitted the leave request. Click on the task shape labeled ‘Line Manager Review’. Expand the shape’s configuration panel and click on the notification tab (4th tab down). It should look like this.leavemanagerreviewEmailData
  27. To edit the notification click on ‘Customise Notification’.
  28. Now we can configure what information the email notification will contain. Click on the context browser icon ‘<+>’.leavemanagerreviewEmailData1
  29. Now under ‘References’ we will see the reference we created earlier.  Under the reference section click on ‘HR.CMN.SMO.LeaveRequest’. This will expand the reference and we will now see all the properties.leavemanagerreviewEmailData2
  30. All these properties can be used in the email notification. Lets start with the ‘Subject’ for the email. In the box under ‘Subject’ enter the following text ‘Leave Request from ‘ and then from the list of properties, drag employee into the box so it’s after ‘Leave Request from ‘. As shown in the image below.leavemanagerreviewEmailData3
  31. Now that we have done the ‘Subject’, we can now edit the body of the email.
  32.  We can just drag in the properties that you want to be shown in the email. In this example I have added the following properties to the body
    1. Employee
    2. Start Date
    3. End Date
    4. Number of Days
  33. I haven’t deleted any of the information that was already in the email. The body of the email should look like the below image.leavemanagerreviewEmailData4
  34. If you want to expand the editor for the body of email click on ‘Open Text Editor’. This will  you a full on text editor to edit the email body.leavemanagerreviewEmailData5
  35. Click on ‘Close Text editor’ to close the editor, once finished. We have now configured the notification email to contain data from the leave request. To help the line manager make their decision on whether to approve the leave request.
  36. We can also do the same for the ‘Approve’ and ‘Reject’ Email. Click on the ‘Reject’ email shape and expand the configuration panel and then drag across any of the reference properties into the email Subject and Body.  rejectedemailData
  37. Do the same for the ‘Approve’ email shape.
  38. Now we have configured all the email notifications to contain relevant data about the leave request.
  39. The next thing we need to do is update the status of the Leave Request, once the line manager has approved or rejected the request so it can be recorded against the request.
  40. To do the update, expand the shape panel and click on ‘Basic’ and then drag the ‘SmartObject Method’ shape on to the canvas.UpdateStatusUpdateStatus1
  41. Click on the ‘SmartObject Method’ shape and then expand the configuration panel on the righthand side of the canvas.UpdateStatus2
  42. Like in setting up the reference, we need to select the ‘SmartObject’ that the shape is going to call. Because we have already used the SmartObject ‘HR.CMN.SMO.LeaveRequest’ will appear already in the list when you click on ‘Select SmartObject’.UpdateStatus3
  43. Now that we have selected which SmartObject we are going to use, we now need to select the correct method. Click on ‘Select Method’, this will show us a list of methods that we can call from the SmartObject. Because we are doing an update we will need to select the ‘Save’ method.UpdateStatus4
  44. Now we need to select which properties we are going to update. Under properties click on ‘+’  and click on the  ‘ID’ and ‘Status’ checkboxes in the list.smopatch
  45. In the box next to ‘Status’ enter in the text ‘Approved’ and  drag the variable ‘LeaveRequestId’ into box next to ‘ID’.patch
  46. As we don’t need to map any return properties  from the SmartObject click on ‘Do not map outputs’ under ‘Output Mappings’.
  47. Click on the 2nd tab in the configuration panel and replace the text ‘SmartObject Method’ under Name with ‘Update Status To Approved’UpdateStatus8
  48. Click on ‘>’ to close the configuration panel and your canvas should look like the below image.UpdateStatus9
  49. We need to link this SmartObject shape into the workflow ‘Approved’ path. To do that just drag it on top of the ‘Approve Email’ shape. UpdateStatus10
  50. You can then choose which order the shapes are stacked by moving them up down the list. The shape at the top of the stack will execute first and then once it has finished, it will then move on to the next shape in stack.
  51. Once you are happy with order of the shapes, your canvas should look like this.UpdateStatus11
  52. Repeat steps 40 – 51 and instead of ‘Approved’ in the status box, enter in ‘Declined’patch1
  53. Change the name of the shape to ‘Update Status To Declined’UpdateStatus13
  54. Drag the shape onto the ‘Reject Email’ shape.UpdateStatus14
  55. Now we can deploy, to do that click on ‘File’ and then click on ‘Deploy’. deploy
  56. You will know it has been deployed Successfully as you will get a message saying it has been successful. deploy1

Linking the Smartforms to the workflow

Now that we have got business data inside the workflow,  we just need to link the  Leave Request form to start the workflow and the Line Manager Review Task to action the task and take the workflow down a specific decision path.

  1. Edit Smartform ‘HR.CMN.SMF.LeaveRequest’ and click on the ‘Rules’ tab.smartform1
  2. Now in the rules tab, click on the rule ‘When btnSubmit is clicked’ and click on ‘Edit’smartform
  3. We now need to add a rule to start the workflow when the submit button is clicked.edit
  4. Click on the ‘Actions’ tab and in the search box enter ‘Start’edit1
  5. Click on the action named ‘Start a Workflow’ it will then appear in the rule execution panel.edit2
  6. Now click on ‘select Workflow’ linkedit3
  7.  A list of workflows on the environment will be listed, expand the folder ‘HR’ and then select the workflow we have created ‘HR.WKF.LeaveRequest’ and then click on ‘Ok’.edit4
  8. Now back in the editor and then click on ‘Configure’.  In the new the window we can configure what data contains in the workflow, such as the leave request Id.edit5
  9. In the context browser expand ‘Parameters’ and drag the parameter ‘Id’ into the box labelled ‘LeaveRequestId’.edit6
  10. In the box labelled ‘Folio’ enter in the following text ‘Leave Request Number ‘ and then drag the parameter ‘Id’ into the same box. So it should look like this.edit7
  11. Click on ‘Next’ and then ‘Finish’ and then ‘Ok’. Click on ‘Finish’ in the top left hand corner to save the form.  We have now setup the Leave Request form to start the approval workflow.finishedform
  12. Now we need to edit the task form to pick up the Line Manager Review actions. This  will be the form that the Line Manager opens up to review the leave request details. The line manager will then either click on the ‘Approve’ button to approve the leave request or the line manager will click on ‘Reject’ to reject the leave request.
  13. In the designer, expand ‘HR’ and then expand ‘Smartforms’ and click on the form named ‘HR.CMN.SMF.LeaveRequestReadOnly’.editleaverequesttask
  14. Click on ‘Edit’.
  15. We are now in the Smartform editor, you will notice that the form has two buttons
    1. Approve
    2. Reject
  16. We are going to link these buttons up to the actions/decisions on the workflow.editleaverequesttask1
  17. Click on the ‘Rules’ tableaverequesttaskrule
  18. Click on ‘Add Rule’
  19. In the events tab click on the event ‘When a control on the form raises an event’buttononclick
  20. In the rule designer click on the blue ‘select control’, from the list select ‘btnSubmit’.buttononclick1
  21. Now click on the ‘Actions’ tab, in the search box enter the word ‘action’ and select the action ‘action worklist item’.buttononclick2
  22. Now click on ‘Select a worklist item’, in the pop up window expand ‘HR’ and the select the workflow we  deployed earlier on in this example. buttononclick3
  23. Expand the workflow and then click on ‘Line Manager Review’ and click on ‘OK’buttononclick4
  24. Now, that we have selected the task, we can now configure what happens when the task is actioned. Click on ‘Configure’buttononclick5
  25. In the context browser ‘expand’ parameters and drag the parameter ‘SN’ into the SN  box and in the ‘Action Name’ enter the text ‘Approve’ as this button is dealing with the ‘Approve’ Action. Click on ‘OK’.buttononclick6
  26. In the actions tab, in the search box enter ‘Close’ and click on ‘Close the browser window’ and click on ‘Ok’. buttononclick7
  27. Now when the ‘Approve’ button is clicked it will tell the workflow to go down the ‘Approve’ decision line and to close the form.
  28. We now need to do the same for the Reject button, select control ‘btnReject’ and repeat steps 19 – 27. Enter in the text ‘Reject’ into the Action Name box.buttononclick8
  29. We have now told the form to handle the response of the buttons to take the workflow down a certain path.
  30. Now we to handle what happens to the task, when form is opened.
  31. In the rule editor click on the rule ‘When the Form is Initializing ‘ and click on ‘Edit Rule’buttononclick9
  32. In the actions tab enter in the word ‘Open’ in the search box and then select the action ‘Open a worklist item’.buttononclick10
  33. Click on open worklist item and select the ‘Line Manager Review’ task, like we did in step 23.buttononclick11
  34. Click on ‘Ok’ and now click on ‘Configure’buttononclick12
  35. Expand Parameters and drag the parameter ‘SN’ to the ‘SN’ box. Click on ‘Next’ and then ‘Finish’ and then click on ‘Ok’.buttononclick13
  36. Click on ‘Finish’ and now we have completed setting up the task form, to interact with the workflow.buttononclick14
  37. All we need to do now is tell the workflow to use the task form and not automatically generated form it will create when the ‘Line Manager Review’ task is activated.
  38. Copy the form url, by clicking on ‘Runtime url’ and then copy the url from the address bar.urlurl2
  39. Now edit the workflow ‘HR.WKF.LeaveRequest’ and click on the shape ‘Line Manager Review’.
  40. Expand the configuration panel for the ‘Line Manager Review’ and click on the 2nd tab.
  41. Under form type select ‘Custom’ and in the URL box copy in the URL we copied from the step 38.url3
  42. Under Parameters click on ‘+’ , as we need to add an additional parameter, so the task form knows which leave request data to load.
  43. Under ‘Serial Number’ enter in the text ‘Id’url5.PNG
  44. Now expand the context browser, if not already expanded and drag the variable into the box next to ‘Id’ and underneath ‘Task Serial Number’ like in the image below.url4
  45. Now when the task form is opened, the form will retrieve the workflow task information and also retrieves the leave request details.
  46. Click on ‘Save’ and then click on ‘Deploy’
  47. We have now completed and finished building  our first app with K2 Five.


Slack and Simple K2 Integration

One of the big messaging apps for team collaboration is Slack and  is perfect platform to demo how to integrate K2 into it. This will be the first article on how we go about doing this.  Slack is free to use and so is great to demo with and it has an ever growing list of third party integration plugins to play with.

So before we start with the demo,what would we expect a K2 slack plugin to behave? I believe it behave in the following way.

  1. Send notifications of tasks that we have to actiontask
  2. Be notified of when task has been completed and what the action was or the workflow has moved to a certain stage or when there is a workflow escalation.
  3. To be able to action a task from inside Slackhomepage_example_hiretron
  4. To be ask Slack what are my outstanding tasks or what is the status of a certain workflow

So lets starts with points 1 and 2 and deal with simple notifications.


Building a Simple messaging app for Slack

Lets start with a simple example, where we can K2 notification messages to Slack, whether its a public message , message to a particular group or a message to an individual person.

First of all we need to sign up for Slack and create a team, which you can down from here . Now we have a slack team, we just need to here  to get access to API for Slack.


We are starting simple, so click on “Incoming webhooks” and then click on the link ‘ incoming webhook integration


Building the web hook url

  1. Choose the channel you want to send the messages to, don’t we will be able to override this later on.

introwebhooks12. Click on the green button ‘Add incoming Webhook integration’

3. You can how see your web hook url, copy that.

introwebhooks24. Further down you can also customize the actual message. I have opted for a K2 look.

introwebhooks35. Click on ‘Save’, we have now created are web hook for incoming messaging.

Slack endpoint assembly

Now we have the web hook, we can how write some code, so K2 can use it. We are going to use a endpoint assembly for this. So we are going to create a class that will take the endpoint and allow us to pass in a message, a optional username and optional group.

private static void PostMessage(Payload payload)
 Encoding _encoding = new UTF8Encoding();
 Uri endpoint = new Uri("web hook here");

string payloadJson = JsonConvert.SerializeObject(payload);
 using (System.Net.WebClient client = new System.Net.WebClient())
 System.Collections.Specialized.NameValueCollection data = 
new System.Collections.Specialized.NameValueCollection();
 data["payload"] = payloadJson;

var response = client.UploadValues(endpoint, "POST", data);

//The response text is usually "ok"
 string responseText = _encoding.GetString(response);

Simple code for posting a payload of information to the web hook url

public static void PostMessage(string text, string username = null, string channel = null)
 Payload payload = new Payload()
 Channel = channel,
 Username = username,
 Text = text


The actual public static method, we will be creating a SmartObject from and then using inside a workflow.

We can then build the solution and take the dll  and now tell K2 about it using the ‘Endpoint Assembly broker’. If you don’t know how to do that view my previous post on creating an Endpoint Assembly.


Now just build a SmartObject that uses the service instance you just created.

Slack SMO

We can test it in the SmartObject tester


When it executes we get this response in Slack


No that the SmartObject has been created, we can now use this method inside a workflow


I am just going to use a simple workflow for this, that has one task and two actions.


We just going to use a SmartObject event to call the Slack notification SmartObject to send a message to the destination user when a task is generated and then a message to the originator when the task is approved or rejected.




We do something similar for the approve and reject activities, except we put in the originator name and the message is that the task has been approved or rejected depending on the activity.

When we run the workflow the destination user gets this message in Slack


With a link to the task, when they action the task the originator will get this message


Next time we will expand on this by making the notifications more advanced and by allowing the user to ask questions about K2.

The source code for this example can be downloaded from here

Next Challenge

It’s that time of the year again where we start to move from those cold winter nights and frosty mornings.  To longer warmer days as we move towards Spring.

For me I am looking for that next  challenge. If your company uses K2 and you need some help whether it be solution design, development of K2 based applications. Or if your organisation is looking to create a centre of excellence within your organisation or you have team members that need to be trained in developing with K2 Blackpearl and Smarforms. Then please get in touch with me  as I am a  K2 Master and I specialise in K2 development and evangelism.

My rates are competive within the K2 market and I am willing to work anywhere in the UK/Europe/World. If you need more than one person then I can also provide your organisation with a K2 development team with each member having in depth knowledge and experience working in the K2 platform

Below is my experience and if you need someone like me in your organisation please email me at or ping me on LinkedIn

With over 17 years experience working on Microsoft based solutions, I have managed and designed solutions for a number of large enterprise clients including the Channel 4,NHS, MOD and NATO.  I am a regular contributor at industry events and have presented at a number of SharePoint conferences.

Working as part of a team, I am highly motivated to produce software that is functional and looks good.  I am security cleared for the Ministry of Defense.

Technologies that I have experience with

C# Crystal Reports
SharePoint 2007,2010,2013 HTML \ XML \CSS
K2 Blackpearl

K2 Appit


WPF Access 97/2000
N-Tier Architecture Object Oriented / Data Modelling
Silver Light ASP \
AJAX IIS \ DNS Administration
SQL Server 00, 05, 08, 12, Azure Office 365
Unit testing VB .net  & VBScript
Entity Framework Linq


Salesforce & Dynamics CRM

Web Services (REST, WCF, Asmx, Azure Data)


  • Project Management
  • Solution Design
  • System Analysis
  • Development
  • Technical deep dive talks
  • Leading Training Sessions
  • Presenting at Key Events
  • Researching new technology
  • Proof of concepts
  • Specification Writing
  • Evangelism

Other Qualifications

  • Certified Scrum Master
  • K2 Master
  • K2 Black pearl Core
  • K2 Smart forms builder
  • K2 Connect
  • K2 Extensions
  • K2 SharePoint
  • MCP in .NET Framework 3.5, ASP.NET Application Development
  • .Net Enterprise Solutions
  • Microsoft Curriculum Certificate (SQL Server)



References and full CV

Available on Request

Best Practice for developing K2 Apps

This guide goes through some  best practices for developing K2 applications.


Below is a list of additional things that are needed for every K2 Smartform.

Form Name

Form name should be made of the following

[ProjectName].[Area].smf.[Name of form]

So for example a form name would look like DMO.TST.SMF.DemoForm


Form Description

The form description needs to be filled in with a basic description of what it does and also its story number and form number. The form number should be in this format < form number >. So for example <FM0001>.  This will make it easier for people to easily identify what the form does what it relates too.






For this project it’s recommended to use concurrently if you do not need to pass data between the actions or rely on the result of the previous action.


Below is a list of additional items needed for a view.

View Name

The name of the view is made up in the same way as a Smartform. The only difference is that instead of .smf.formname.  The instead of ‘.smf’ its one of the following

[ProjectName].[Area].vwi.[Name of view]


View Type


Item View VWI
List View VWL


View Description

The view description needs to be filled in with a basic description of what it does and also its story number.  This will make it easier for people to easily identify what the view does what it relates too.


View Properties

View input controls and labels are in the same column.


View Controls

The controls for the view also has naming conventions

Display Controls

Type Property Name Size Example
Content ctt cttMyControl
Label lbl 200px lblMyControl
Picture pic picMyControl

Input Controls

AutoComplete auo 200px auoMyControl
Calendar cal 100px calMyControl
Check Box chk 150px chkMyControl
Check Box list chl 150px chlMyControl
Choice che 200px cheMyControl
Data Label dbl 200px dblMyControl
Drop-Down list ddl 200px ddlMyControl
Hyperlink hyp 200px hypMyControl
List Display lst 200px lstMyControl
Lookup lku 200px lkuMyControl
Multi-Select msl 300px mslMyControl
Picker pkr 200px pkrMyControl
Radio Button rdo 150px rdoMyControl
Radio Button Group rdg 150px rdgMyControl
Radio Button list rdl 150px rdlMyControl
Rating rtg 150px rfgMyControl
Rich Text rxt 400px rxtMyControl
Slider sld 150px sldMyControl
Text Area tar 400px txtMyControl
Text Box txt 200px txtMyControl
Tree tre treMyControl

Action Controls

Button btn btnMyControl
Timer tmr tmrMyControl
Toolbar Button tbr tbrMyControl

Attachment Controls

File Attachment fat fatMyControl
Image Attachment iat iatMyControl

Layout Controls

Table tbl tblMyControl

The size is only a guide and common sense must still be used for controls apart from the label control.


Control Watermarks

Each control should have its own watermark, with the watermark relating the label the control belongs to and not just the default ‘Type a value’

The watermark must be all in lower case

The image below should help demonstrate this



When to use a drop down list or a picker control

Using drop down lists to select reference data and for most cases is an acceptable approach as everybody knows now to use a drop down list. But it does have a couple of drawbacks.

  1. Can take the form a long time to load if there is a huge amount of data to populate the drop down list
  2. When the user interacts with a dropdown list with huge amount of data, the drop down list becomes a nightmare to interact with.

So we do have an answer to this and that is to use to the picker control instead. This will allow for speedier loading times and also allows the user to search for the specific data in an easier fashion.

The rules for moving to a picker control is if the reference data is longer than 20 rows then use a picker control. You still setup the control in exactly the same way as you would a drop down list. The only differences you can choose which properties can be searched against.

Setting up a picker control

1.Drag  a picker control on to the view or change an existing control into a picker control




2.Give the control a  name with the correct naming conventions

3.Select ‘SmartObject’ under data and setup as normal if you would a drop down list

4.Select which properties you want to filter against


5. Click ‘Ok’


6. In the picker control properties unchecked ‘Allow Multiple’


Required fields

If a control is required, we can graphically represent this by adding a *. To do this do the following steps.

  1. Select the label of the  field/control you want to modify
  2. In the properties tab, find the ‘Text’ property
  3. At the end of the text, put in the following html ‘<b style=’color:red’>&nbsp;*</b>’
  4. Literal property is enabled
  5. In the ‘Tooltip’ put in the text of the label without the html ‘<b style=’color:red’>&nbsp;*</b>’.




Control Data Cache

Please make sure that data caching is not enabled on your data list controls like dropdown lists etc…


Label to Control spacing

As mentioned in the table at the beginning of ‘View Controls’ the labels must set to 200px with the ’Wrap Text’ property value set to ‘True’


Read Only Controls

Data that is read only will be data labels with ‘Read Only’ enabled and with a name that starts with ‘dblReadOnly’

So for example a ‘Lastname’ needs to be read only, it would be called ‘dblReadOnlyLastname’


View Rules

The pattern for RCT is that we have smart views and dummy forms. So to get this to work properly we have use unbound rules.


How to create a unbound rule

Unbound rule is something that is not bound to an event such as a button is clicked.

To create unbound rules do the following steps

  1. Click on Rules, ‘Add Rule’
  2. In the right hand panel and click on ‘Enter Rule Name’ as seen in the image below


3. Start the Rule name with the word ‘Unbound’ and the rest of the rule name should be what it does.

4. You can then add in conditions and actions as normal

Reducing the load with editable list views

Due to the amount of rules being called on an editable list, there is new approach that dramatically reduces those calls.

1.Create a list view, but don’t enable the editing options


2.On the view layout, drag a couple of ‘Toolbar buttons’ on the to the top of the view and name them ‘Add’ and ‘Edit’


3.Add a parameter for the primary key of the data the list view is bound to

4.Click on ‘Finish’

5.Create an item view based on the same SmartObject that was used for the list view.


6.On the item view add  a button and lets call ‘Save’

7.Add a parameter with same name and type that you used in the list view.


8. Add in any other additional parameters you will require such the rest of the best practice parameters.

9.Click on ‘Rules’ and click on ‘Add Rule’

Event When a view executes a method  initialize
Condition If the view parameter contains a value  (Primary key parameter)
Action Execute a view method Load
Input Parameter ID
Parameter Value View primary key parameter


10.Click on ‘Ok’

11.Create a unbound rule to check the validation of the view

12.Create an unbound rule to either save or update the data depending on if the parameter id is populated like in step 9.


13. Now create a rule for when the save button is clicked which will check for the view validation rule and then call the ‘Unbound Save Data‘ rule that you just created.


14. Now that we have built the rules to save and update and load the information we can now add it to the list view. Open the list view in ‘Edit’ mode and go to the rules

15. Create a unbound view called ‘Unbound PopUp View

Rule Name Unbound PopUp View
Action Open Subview (Select your item view you just created)
Configure Execute a view method Load
Source Parameter List View Primary Key parameter
Destination Parameter Item View primary key parameter



16. Now create rule for the ‘btnAdd’ that calls the unbound rule

Event Control on view raises an event
Action Transfer Data


Parameter Primary Key value
Parameter Value Empty (Tick the check box, but leave empty)
Action Execute another rule Unbound PopUp View


17. Do the same for the ‘btnEdit’ except without the ‘transfer data’ action


18.Create a rule that when you click on the list item it transfers the primary key from the list into the view parameter.



19.The last set of rules we need to do is add an action to close the sub view once the ‘Save’ button has been clicked. Click on the ‘btnSave is clicked’ rule and click on ‘Edit’

20. Click on the ‘Actions’ tab and search for ‘Close’ and select ‘Close Subview’ action. The edit rule should look like this.


21. Click on ‘Ok’ and ‘Finish’

22.You can now test the view to make sure it’s behaving correctly. When you click on ‘Add’ it should load up the item view empty and when you click on ‘Save’ it should insert a new record into the list. If you click on an item in the list and click on ‘edit’ it should load up the data for you to edit. When you click on ‘Save’ it should update any changes.



This section looks at what is needed in every workflow

Where to create the workflow?

The workflow is to be created in visual studio, so it can be checked into TFS

Workflow Name

The name like the views and Smartforms must represent what part of the project it relates to

[ProjectName].[Area].wf.[Name of workflow]

Workflow Description

Work flow description should be filled in, so people know what it does and what story it relates to

Workflow Data fields

Data fields should be kept to a minimum and be used to only hold reference data like a primary or foreign key. You can then use ‘reference option’ to get the rest of the data that you need.

The following check boxes also need to be unchecked

  • Hidden
  • On Demand
  • Keep Audit


Workflow Activities

Workflow activities should contain a name in what they do and the activity description should contain information such as whether there is a start rule or any escalations.

To describe what activity rules are being used you can use the following abbreviations

Activity Rule


Proceeding Rule PR
Start Rule SR
Escalation Rule ER
Destination Rule DR



Activities are colour coded to make it easier to identify what they are doing

Activity Type

Activity Colour

Start Green
Client Activity Blue
Server Activity Grey
IPC Activity Yellow
End Activity Red


Activity Events

Activity Events should say what they are doing and not be left with the default names

If a server event is used with some code then the event name should be prefixed with ‘CC’

Please note it is not ideal to put code directly into the workflow and you must consult with your K2 lead before doing so.


Line Rules

Lines Rules must have a label that is prefixed with LR and then what the rule is checking for. As seen in the image above.


Line Colours

The outcome lines should also be coloured to represent what they are doing and to also help visually navigate what the workflow is doing. This is especially helpful in larger workflows

Line Type


Approve (Positive Line) Green
Reject (Negative Line) Red
Rework line Blue
Normal line Default





This sections looks at what is needed in each SmartObject. If you have a number of stored procedures that interact with same table, then same SmartObject can be used with the additional methods and properties added.

Where to create a SmartObject

SmartObject should be created in visual studio and in the correct folder

SmartObject Name

The name of the SmartObject like the rest of the K2 artefacts should carry the same naming convention.

[ProjectName].[Area].smo.[Name of SmartObject]

SmartObject Description

The description of the SmartObject should describe what it does and what story it belongs to.

SmartObject Parameters

All required input properties should be parameters and be prefixed ‘p’

SmartObject Properties

  Naming Conventions

The property names must be named correctly with no ‘PropertyName(1)’ used

There should be no names with spacing between words or no _ . Camel case should be used

  Property Description

A description of the property used be filled in describing what the property does.

  Property Data types

The correct property type should be used and most of the time K2 will take care of this automatically. The only exception is for file types. You will need to manually change the property data type for the file property from ‘Memo’ to ‘File’


When creating a method the following needs to be checked.

Method Name

The name should represent what it does

Method Description

Should describe what the method does and what store procedure it is calling

Method Types

In some cases the correct method type is not selected. After the service object method is collected.


So you once the service object method has been selected and the properties created and bound to the service object. You need to edit the method and choose the correct method type.

An example of this sometimes a store procedure that returns a single row of data is sometimes returned as a list method. This is incorrect and would cause problems later on in the view design.

So in this case you would need to change the method type to ‘Read’ and then save.


Testing SmartObjects

After creating the SmartObject, it can be tested by using the SmartObject Service Tester which if its not on your task bar it can be found here ‘C:\Program Files (x86)\K2 blackpearl\Bin\SmartObject Service Tester.exe’



Using this application allows you then to test your SmartObject to see if it is working correctly.


How to test your SmartObject

To test your SmartObject do the following

  1. Open the tester tool
  2. Expand ‘SmartObject Explorer’
  3. Navigate to your SmartObject
  4. Right Click on the object and select ‘Execute SmartObject’


5.From here we can now test the methods of the SmartObject. Select a method from the dropdown list and fill out the parameters as required and then click on ‘Execute’

6.The returned data if there is any will be returned in the underneath the parameters.