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 developers to rethink how they build their workflows. The previous web-based designer in K2 blackpearl was aimed at citizen developers. The new one is aimed at them and at professional developers as well.
The K2 Five workflow designer has all the power of K2 Studio, with the benefit of being entirely web-based. There’s no need to install client tools on a developer’s PC, or to install the Silverlight plugin on a compatible browser, as it is all HTML5 now.
Case study
GreenEggs Studio needs a simple annual leave request solution to replace their existing paper-based system. They have decided to use K2 because of its 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 to get the leave request out into the business as quickly as possible, so they are taking an agile MVP approach. That way they can iterate and add features based on user feedback instead of assumptions.
The process map looks like this:
As you can see, it’s a very simple process.
- An employee fills out and submits the annual leave form.
- Their line manager receives an email asking them to review the request.
- If the line manager declines the request, the employee receives an email saying it has been declined and the status is updated.
- If the line manager approves it, the employee receives an email saying it has been approved and the status is updated.
Getting started: a simple workflow
So let’s get started with designing a workflow in K2 Five. We are going to build a simple workflow for annual leave requests. The SmartForms and SmartObjects have already been built.
- Go to the K2 Five Designer and click on ‘Workflow’.
- The workflow design wizard will load and ask you to enter a name and the location where you want the workflow to be saved.
- Let’s give the workflow a name like ‘HR.WKF.AnnualLeave’. I name workflows this way so we can identify which solution the workflow belongs to, in this case the ‘HR’ solution.
- Now let’s choose the location. Click on the blue ‘workflow’ link underneath the workflow name and a window will pop up showing a list of folders.
- Select the ‘HR’ folder and click on ‘OK’. If there isn’t a folder there already, click on ‘Create Folder’ and enter the name ‘HR’.
- On ‘OK’, the folder window will close and the folder location under the name will say ‘HR’.
- Now click on the ‘Create’ button, which takes us into the new design canvas.
- When the canvas loads, we are presented with a Smart Assist helper that gives a brief introduction to the new workflow designer. You can click the left and right arrows to view the helpful clips, then click on close when you have finished.
- Welcome to the new K2 Five workflow designer 🙂
- Smart Assist is always present in the new designer, and when you are new to it, it will suggest what to do next. You can click ‘x’ to close it for this workflow, or click ‘Got It’ and it will assume you know what you are doing. In this case I am just going to click ‘x’ to close it.
- Once Smart Assist is closed, the first thing you will notice is how simple the designer looks. If you have used K2’s previous workflow designers, both web and Studio, a couple of things are very different. Activities, steps and events are gone, replaced with ‘shapes’. So throughout the rest of this guide I will use the term ‘shape’ instead of event. For example, ‘I am going to drag the email shape onto the canvas’ instead of the email event.
- On the canvas we start with the ‘Start’ shape, and you can see it has put a marker where we can place the next shape.
- Now we have a canvas to build the annual leave process on. On the left-hand side of the canvas is a toolbox of all the shapes the workflow can use, like creating a task, sending an email and so on. To view the shapes, click on ‘>’ to expand the toolbox.
- The first shape we are going to use is a Task. Drag the task shape into the placeholder on the canvas. A ‘!’ exclamation mark will be displayed against the task shape. Don’t worry about that, K2 is just letting us know it’s not configured yet.
- Now click on the Task shape on the canvas, and the configuration panel icons on the right-hand side will change to show the task’s configurable options.
- Click on ‘<’ on the configuration panel to expand the options.
- The first tab in the task configuration is where we can give some instructions to the person (or people) receiving the task. It is also where we say what actions they can perform.
- So let’s add some basic instructions: “Please review the details of the leave request and either click on ‘Approve’ or ‘Decline’.”
- Next we are going to add the actions for the task. For standard actions like ‘Approve’ and ‘Reject’, K2 has made it easy by giving us default options we can just click on to create the actions.
- So let’s click on ‘Both’. The actions will appear and Smart Assist will pop up showing how to create action paths. Click ‘x’ to close Smart Assist.
- Now click on the next tab in the configuration options. Here we can choose which form will be used for the task. The options are: Basic Task Form, where K2 autogenerates a form that lets the user choose an action; SmartForm, where we select an existing SmartForm from the library; Custom, where we enter the URL of the form we are going to use; and No form, as it is possible to have a task with no form at all.
- For now we are going to use ‘Basic Task Form’. We will come back later and change it to a specific form.
- Next we choose who will receive the task, so click on the next tab to choose the recipient.
- By default the task will go to the person who submits the leave request, so we need to change this to their line manager. Click on ‘Originator’ and select ‘Originator Manager’ from the list. Now, when the task is generated, it will go to the manager of the person who submitted the leave request.
- Looking at the process map, the line manager also needs an email notification to say they have a leave request to complete. Click on the next tab down, the one with the letter icon. Here we can decide whether the line manager gets an email notification. We can use the standard notification email, or click on ‘Customise Notification’ and create a custom email that includes business data relevant to the task. For now we will use the standard notification.
- 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.
- Double-click on the word ‘Task’ and replace the text with ‘Line Manager Review’.
- To create the decision branches, left-click and drag from the bottom of the task shape to create a new line and placeholder.
- Now drag the blue diamond (the decision shape) into the placeholder. K2 will pick up that we have two actions from the previous shape and automatically create the decision outcomes based on those actions.
- Now let’s deal with the ‘Rejected’ branch.
- In the process map, when a leave request is rejected we need to send an email to the employee who submitted it. From the toolbox on the left-hand side, drag the email shape onto the canvas.
- Left-click on the orange dot next to ‘Rejected’ and drag it onto the email shape we just added.
- Now let’s configure the email. First, double-click on the ‘Send Email’ text and enter ‘Reject Email’.
- Click on the email shape again and expand the configuration panel on the right-hand side.
- We don’t need to change ‘To’, as it is already set to ‘Originator’, which is the person who submitted the leave request form.
- In the Subject, enter ‘Leave Request Status’.
- In the Body, for now just enter: ‘Hi, your leave request that was submitted to your line manager has been declined.’ We will come back to this later and add some business data from the actual leave request, but for phase 1 we will keep it very simple.
- Now let’s do the ‘Approved’ branch. As with the rejected branch, drag another email shape from the toolbox onto the canvas.
- Drag the orange ‘Approved’ dot to the new email shape.
- Click on the email shape and expand the email configuration panel on the right-hand side of the canvas.
- In the Subject enter ‘Leave Request Status’, and in the Body enter: ‘Hi, your line manager has approved your leave request.’
- Now click on the next tab in the email configuration panel. Here we can change the name of the email shape, and we can also enter additional notes about it.
- In the name section, remove the text ‘Send Email’ and change it to ‘Approve Email’.
- We have now configured the email for when the line manager approves the leave request.
- To finish off the workflow we need to add an ‘End’ shape. In the toolbox it’s the red square. Drag it onto the canvas underneath the other shapes.
- Now connect the ‘Approve Email’ and ‘Reject Email’ shapes to the end, just as we connected the decision branches to the email shapes: left-click and drag from the bottom of each email shape to the end shape.
- We have now completed a very simple version of the leave request. The leave request gets submitted. The line manager of the user who submitted it receives an email asking them to approve or reject it. The user then gets an email telling them what their line manager decided.
Using SmartObjects inside the leave request workflow
- The leave request has a SmartObject, HR.CMN.SMO.LeaveRequest. This holds the leave request details, like leave dates, number of days, status, who created it and when.
- So let’s edit the workflow we created earlier to use the data from HR.CMN.SMO.LeaveRequest. To do this we need to add a variable to hold the leave request number, so the workflow can find the correct leave request details.
- Click on the ‘Start’ shape and then on the configuration panel on the right-hand side of the canvas. Then click on the ‘<+>’ symbol in the top right corner.
- This expands the Context Browser for the canvas. The Context Browser shows any references, variables and environment fields currently used in the workflow. It also gives you access to workflow details and workflow functions.
- As this is the first time we have used the Context Browser in this workflow, we just get a brief description of what references and variables are. Under Variables, click on ‘Add Variable’.
- A new variable called ‘New Data Field’ is created. Click on the text ‘New Data Field’, delete it and replace it with ‘LeaveRequestId’.
- Next we need to change the data type of this variable. At the moment it is set to ‘Text’, and we need it to store a number, so click on ‘…’ and then ‘Settings’.
- We are now in the settings for the variable. Under ‘Data Type’ you will see it says ‘Text’.
- Click on the drop-down list under ‘Data Type’, choose ‘Number’ and click ‘OK’.
- We have now created and configured a variable to hold the related leave request number. Next we need to tell the workflow which data to retrieve, by creating a shortcut to the SmartObject HR.CMN.SMO.LeaveRequest.
- Expand the shape toolbox on the left-hand side of the canvas and click on ‘Basic’.
- We will now see all the shapes in the ‘Basic’ category. The one we want is called ‘Create Reference’. Click and drag it onto the canvas.
- Click on the ‘Create Reference’ shape and expand the configuration panel on the right-hand side. The first thing we have to do is select a SmartObject.
- Click on ‘Select SmartObject’, which brings up a window to choose the category where the SmartObject is stored.
- The SmartObject we want is under ‘HR’ – ‘SmartObjects’. Click on ‘HR’, then ‘SmartObjects’, select HR.CMN.SMO.LeaveRequest and click ‘OK’.
- Now we need to choose which method the reference will use to get the correct data. Click on ‘Select Method’ and select ‘Load’.
- Because we have selected the ‘Load’ method, it needs some input to retrieve the correct row of data. In this case it needs a value passed into the property named ‘ID’.
- If the Context Browser is not expanded, click on the ‘<+>’ symbol in the top right corner of the panel. You will see the variable we created earlier. Drag it into the box labelled ‘Type / Drop’ next to the ‘ID’ property.
- We have now configured the reference to retrieve the data where ‘ID’ matches the value of the ‘LeaveRequestId’ variable. If you know SQL, we are essentially doing this: Select * from HR.CMN.SMO.LeaveRequest where ID = @LeaveRequestId.
- Click on the next tab in the configuration panel and, under ‘Name’, replace ‘Create Reference’ with ‘Leave Request Details’.
- Click on ‘>’ to close the configuration panel. We have now created a shortcut to the leave request data. Next we need to link the reference into the workflow, so it retrieves the correct data before the line manager’s task is created.
- On the canvas, disconnect the line going from the ‘Start’ shape to the ‘Line Manager Review’ shape.
- Drag the ‘Leave Request Details’ reference shape in between ‘Start’ and ‘Line Manager Review’. Connect the line from ‘Start’ to ‘Leave Request Details’, then left-click and drag a line down from the bottom of ‘Leave Request Details’ to the top of ‘Line Manager Review’.
- Now that the workflow has access to the details entered in the leave request form, we can give some context to the emails the workflow sends out.
- Let’s start with the email notification to the line manager. Click on the ‘Line Manager Review’ task shape, expand its configuration panel and click on the notification tab (the fourth tab down).
- To edit the notification, click on ‘Customise Notification’.
- Now we can configure what information the email will contain. Click on the Context Browser icon ‘<+>’.
- Under ‘References’ you will see the reference we created earlier. Click on ‘HR.CMN.SMO.LeaveRequest’ to expand it and see all of its properties.
- All of these properties can be used in the email notification. Let’s start with the Subject. In the box under ‘Subject’ enter the text ‘Leave Request from ’ and then drag ‘Employee’ from the list of properties into the box, after that text.
- With the Subject done, we can now edit the body of the email.
- Just drag in the properties you want shown in the email. In this example I have added Employee, Start Date, End Date and Number of Days.
- I haven’t deleted any of the information that was already in the email.
- If you want a bigger editor for the email body, click on ‘Open Text Editor’, which gives you a full text editor.
- Click on ‘Close Text Editor’ when you have finished. We have now configured the notification email to contain data from the leave request, to help the line manager decide whether to approve it.
- We can do the same for the approve and reject emails. Click on the ‘Reject Email’ shape, expand the configuration panel and drag any of the reference properties into the email Subject and Body.
- Do the same for the ‘Approve Email’ shape.
- All the email notifications now contain relevant data about the leave request.
- Next we need to update the status of the leave request once the line manager has approved or rejected it, so the decision is recorded against the request.
- To do the update, expand the shape panel, click on ‘Basic’ and drag the ‘SmartObject Method’ shape onto the canvas.
- Click on the ‘SmartObject Method’ shape and expand the configuration panel on the right-hand side of the canvas.
- As with the reference, we need to select the SmartObject the shape is going to call. Because we have already used HR.CMN.SMO.LeaveRequest, it will already be in the list when you click on ‘Select SmartObject’.
- Now we need the correct method. Click on ‘Select Method’ to see the methods we can call on the SmartObject. Because we are doing an update, select the ‘Save’ method.
- Next, select which properties we are going to update. Under Properties click on ‘+’ and tick the ‘ID’ and ‘Status’ checkboxes.
- In the box next to ‘Status’ enter ‘Approved’, and drag the ‘LeaveRequestId’ variable into the box next to ‘ID’.
- We don’t need to map any return properties from the SmartObject, so click on ‘Do not map outputs’ under ‘Output Mappings’.
- Click on the second tab in the configuration panel and replace ‘SmartObject Method’ under Name with ‘Update Status To Approved’.
- Click on ‘>’ to close the configuration panel.
- We need to link this SmartObject shape into the ‘Approved’ path. To do that, just drag it on top of the ‘Approve Email’ shape.
- You can then choose the order the shapes are stacked in by moving them up and down the list. The shape at the top of the stack executes first, and once it has finished the next shape in the stack runs.
- Once you are happy with the order of the shapes, repeat the same steps for the declined path: add another SmartObject Method shape, but enter ‘Declined’ in the status box.
- Change the name of the shape to ‘Update Status To Declined’.
- Drag the shape onto the ‘Reject Email’ shape.
- Now we can deploy. Click on ‘File’ and then ‘Deploy’.
- You will know it has deployed successfully, as you will get a message saying so.
Linking the SmartForms to the workflow
Now that we have business data inside the workflow, we just need to link the leave request form to start the workflow, and link the Line Manager Review task form so it actions the task and sends the workflow down the right decision path.
- Edit the SmartForm ‘HR.CMN.SMF.LeaveRequest’ and click on the ‘Rules’ tab.
- In the Rules tab, click on the rule ‘When btnSubmit is clicked’ and click on ‘Edit’.
- We now need to add a rule to start the workflow when the submit button is clicked.
- Click on the ‘Actions’ tab and enter ‘Start’ in the search box.
- Click on the action named ‘Start a Workflow’ and it will appear in the rule execution panel.
- Now click on the ‘select Workflow’ link.
- A list of the workflows on the environment will appear. Expand the ‘HR’ folder, select the workflow we created, ‘HR.WKF.LeaveRequest’, and click ‘OK’.
- Back in the editor, click on ‘Configure’. In the new window we can configure what data is passed to the workflow, such as the leave request ID.
- In the Context Browser, expand ‘Parameters’ and drag the ‘Id’ parameter into the box labelled ‘LeaveRequestId’.
- In the box labelled ‘Folio’, enter the text ‘Leave Request Number ’ and then drag the ‘Id’ parameter into the same box.
- Click on ‘Next’, then ‘Finish’, then ‘OK’. Click on ‘Finish’ in the top left-hand corner to save the form. The leave request form will now start the approval workflow.
- Next we need to edit the task form to pick up the Line Manager Review actions. This is the form the line manager opens to review the leave request details. They will click either ‘Approve’ to approve the leave request or ‘Reject’ to reject it.
- In the designer, expand ‘HR’, then ‘SmartForms’, and click on the form named ‘HR.CMN.SMF.LeaveRequestReadOnly’.
- Click on ‘Edit’.
- We are now in the SmartForm editor, and you will notice the form has two buttons: Approve and Reject.
- We are going to link these buttons up to the actions/decisions in the workflow.
- Click on the ‘Rules’ tab, then ‘Add Rule’.
- In the Events tab, click on the event ‘When a control on the form raises an event’.
- In the rule designer, click on the blue ‘select control’ and select ‘btnSubmit’ from the list.
- Now click on the ‘Actions’ tab, enter the word ‘action’ in the search box and select the action ‘action worklist item’.
- Click on ‘Select a worklist item’. In the pop-up window, expand ‘HR’ and select the workflow we deployed earlier.
- Expand the workflow, click on ‘Line Manager Review’ and click ‘OK’.
- With the task selected, we can configure what happens when it is actioned. Click on ‘Configure’.
- In the Context Browser, expand Parameters and drag the ‘SN’ parameter into the SN box. In ‘Action Name’ enter ‘Approve’, as this button deals with the ‘Approve’ action. Click ‘OK’.
- In the Actions tab, enter ‘Close’ in the search box, click on ‘Close the browser window’ and click ‘OK’.
- Now when the ‘Approve’ button is clicked, it will tell the workflow to go down the ‘Approve’ decision line and close the form.
- We need to do the same for the Reject button. Select the control ‘btnReject’ and repeat the steps we followed for the Approve button, entering ‘Reject’ in the Action Name box.
- The form now handles the buttons and takes the workflow down the right path.
- Next we handle what happens to the task when the form is opened.
- In the rule editor, click on the rule ‘When the Form is Initializing’ and click on ‘Edit Rule’.
- In the Actions tab, enter the word ‘Open’ in the search box and select the action ‘Open a worklist item’.
- Click on ‘Open a worklist item’ and select the ‘Line Manager Review’ task, as we did for the Approve button.
- Click on ‘OK’ and then ‘Configure’.
- Expand Parameters and drag the ‘SN’ parameter to the ‘SN’ box. Click on ‘Next’, then ‘Finish’, then ‘OK’.
- Click on ‘Finish’, and the task form is now set up to interact with the workflow.
- All we need to do now is tell the workflow to use this task form, instead of the form it generates automatically when the ‘Line Manager Review’ task is activated.
- Copy the form URL by clicking on ‘Runtime url’ and copying the URL from the address bar.
- Now edit the workflow ‘HR.WKF.LeaveRequest’ and click on the ‘Line Manager Review’ shape.
- Expand the configuration panel for ‘Line Manager Review’ and click on the second tab.
- Under form type select ‘Custom’, and paste the URL we copied earlier into the URL box.
- Under Parameters click on ‘+’, as we need to add another parameter so the task form knows which leave request to load.
- Under ‘Serial Number’ enter the text ‘Id’.
- Expand the Context Browser, if it isn’t already, and drag the variable into the box next to ‘Id’, underneath ‘Task Serial Number’.
- Now when the task form is opened, it will retrieve the workflow task information and the leave request details.
- Click on ‘Save’ and then ‘Deploy’.
- We have now finished building our first app with K2 Five.