Part 3: Workflow
In Part 3 of this tutorial, you will edit your Leave Request Workflow by expanding the system tasks and by adding an additional manager approval outcome to rework the request. You will learn about escalations and how they can be used to remind a user of a task waiting to be actioned. You will also be tweaking the forms in the application to behave differently depending on where in the workflow the form is being used.
In this part, you will learn:
- How to add additional system tasks for sending email notifications
- How to customize an email task notification message body
- How to add an additional outcome and configure a new user task for responding to that outcome
- How to implement a rework loop in a workflow
- How to add an escalation to a user task
- Tweaking form rules for workflow integration
(If you have not completed Part 2: Forms of this tutorial yet, please do so before continuing with this part.)
In Step 5, you will replace the two Placeholders with email events that notify the originator with the manager's decision.
Step 5 Tasks
- Add a Send E-mail event to the approved outcome event, replacing the existing Placeholder. Route the email to the Originator Email.
- Customize the subject line and message body using Item References properties. You may structure the content in any manner you like; the image below is an example to use as a guide.
- Delete the Placeholder event for the rejected outcome. Add a new continue outcome, then copy and paste the approved email event into the rejected event box. Edit the rejected email event to reflect the rejected decision.
- In K2 Designer, edit the Leave Request Workflow. (Right-click the workflow name in the category tree, then select Edit.)
- Click the Workflow Steps tab to expose the wizards if it is not already open. Drag a Send E-mail event into the approved outcome Placeholder event. Click Yes, for the confirmation dialog that asks if you want to change this step.
- The e-mail event wizard opens. Expand the Context Browser, then Workflow Context. Drag the Originator Email into the To field.
- For the Subject line, enter the following text, replacing the bracketed text [Title] with the Item Reference > Leave Request SmartObject > Leave Request Title found in the Context Browser.
Your Leave Request is Approved: [Title] - Using the same approach as above, enter the following content into the message body, again replacing the bracketed text with the appropriate Item References properties from the context browser.
Your Leave Request has been approved by your manager. Your request details are as follows:
Leave Start Date: [Leave Start Date]
Leave End Date: [Leave End Date]
Leave Type: [Leave Type]
Approver Comments: [Approver Comments] - Double-click the Placeholder title of the step and change it to
Email Originator Approved - In the basic Leave Request tutorial, you copied and pasted events to speed up the build process. You will do the same here. Begin by deleting the rejected side Placeholder so that you can paste the e-mail event you just created in its place. Right-click the Placeholder1 event and select Delete. Click Yes for the confirmation dialog that appears.
- Next, you need to add back in the Continue outcome line, which will add a corresponding event holder. Hover over the Set Status Rejected event until you see the Workflow Step Outcomes icon (it looks like a blue mini-flowchart). (If you don't see the icon when hovering, click anywhere on the design canvas to refocus your mouse to the canvas, then try hovering again.) Click the icon when you can see it.
- On the Workflow Step Outcomes configuration screen, click Add. Replace New Outcome with
Continue
then click OK. You should now see the continue line with an empty event box. - Copy the E-mail event you just configured. To copy an event in K2 Designer, click outside of the event box, then drag over the event to highlight it. Click Copy when the option menu opens. (If you get a dialog about allowing access to the clipboard, click Yes to continue.)
- Right-click inside the empty event box and click Paste. You should now see the Email Originator event has been replicated. You need to make a few adjustments to reflect the rejected outcome.
- Double-click the event to open its wizard. Change the Name to
Email Originator Rejected
then click Next. - There are no outcomes to configure, so click Next. Change the Subject line and the message body to reflect the manager's rejected decision. Use the image below as a guide, the changed values are underlined in red. Click Finish when ready.
Your email should look like the image below. Click OK when ready.
STEP 5 REVIEW
In this step, you added an email event and customized the email using properties found in the context browser. The placeholder values from the context browser (indicated by green blocks in the wizard screens) will be replaced at runtime by K2 with the actual values for that instance of the workflow. The workflow context offers properties that contain details about the workflow itself, such as the workflow originator, originator's email, manager, folio and so on. Item references contain SmartObject property references. For example, the [Leave Request Title] item reference is replaced at runtime with whatever value was entered into the form's Leave Request Title field. This allows you to customize and personalize your workflow. You also discovered the ease of reusing content by copying and pasting events.
In this step, you are going to add an additional outcome for the manager approval task. This third outcome, called Rework, will send the request back to the originator where it can either be resubmitted or canceled. You will add a new user task for the form originator to action the rework task, then add events to complete the rework decision outcomes.
Step 6 Tasks
- Add a third outcome to the manager approval task and name it
Rework
and allow the user to action the task without opening the form. - Customize the manager's task notification email in any manner you like. You may use the image below as a guide.
- Add a User Task (SmartForms) to the rework event box. Name the new task
Rework Request
then add the following actions:
Resubmitted
Canceled - Use the Leave Request form for the rework form and route the task to the Originator.
- Change the Resubmitted outcome so that it routes to the Set Status Submitted event.
- Copy and paste the Set Status Submitted event into the empty event for the Canceled outcome. Remove the continue outcome for the cancel event as you want the workflow to end at this point. Change the Request Status value to
Canceled
leaving the ID value set as it is.
- Double-click the Manager Approval user task to open its wizard. Enter a third action and name it
Rework
then confirm the option to Allow user to action the task without opening the Form is CHECKED. Confirm the option to Automatically generate Outcomes for the above Actions is CHECKED. Click Next to continue. - There are no changes to the Linked To values, so click Next. The Leave Request Form is correct, so click Next. There are no changes to the work item rules, so click Next. There are no changes to the Participants, so click Next.
- On the Event Notification Settings screen (email message/body content) CHECK the box to Customize the Notification Message. Notice that after you check the box, K2 adds the default task notification content in the message body. You are going to add additional text to the email so that the manager can approve, reject or rework the request using SmartActions.
- Drag a User Task (SmartForms) event into the new rework event box.
- The User Task wizard opens. Name the new event
Rework Request
and enter the following for the Instruction:
Your manager has requested that you rework your Leave Request. You may resubmit or cancel the request.
For the actions, enter
Resubmitted
Canceled
then click Next. - The Leave Request Form is correct, so click Next. There are no changes to the work item rules, so click Next.
- On the Participants screen, drag the Originator into the Task Group box. CHECK the box to Notify participants when they receive a work item. To save time you will not customize the email content, so click Finish.
- Double-click the Rework Request user task to open its wizard. Click Next from the home screen. Change the Linked To value for the Resubmitted outcome to Set Status Submitted. Click Next until you can click Finish to complete this step (three times).
- Copy and paste the Set Status Submitted event into the Canceled event. (See Step 5 (j) if you need a reminder on how to copy and paste events in K2 Designer.)
- Double-click the new Set Status Submitted1 event to open its wizard. Change the name to
Set Status Canceled
then click Next. - On the Workflow Step Outcomes screen, CHECK the box next to the Continue2 outcome and click Remove. (Depending on how you've worked through the steps, your outcome may have a slightly different name from Continue2.) Click Next.
- Click Next to reach the input properties screen, then scroll down and change the Request Status value to
Canceled
then click Next. You do not need to change the ID value as it is telling K2 which record you want to update (the current record). Click Finish when ready. - Your completed workflow should look like the image below.
- Save your work. (File > Save)
For this step, you will add text to the notification email and customize the subject line. For the subject line, enter
Leave Request Submitted: [Leave Request Title]
then drag the Item References > Leave Request SmartObject > Leave Request Title to the end of the subject line, replacing the bracketed text. (See the image below as a reference if necessary.)
In the message body, just below the Dear Participant line, enter the following, dragging values from the context browser as needed for the fields contained in brackets.
A Leave Request has been submitted and now requires a decision by you. Please review the following details, then reply to this email with one of the decision actions as the email message body.
Employee Name: [Employee Name]
Leave Start Date: [Leave Start Date]
Leave End Date: [Leave End Date]
Leave Type: [Leave Type]
(Click Finish when ready.)
Notice that K2 has added a third action outcome with an event box. You will now add a user task for the form originator to either resubmit or cancel the request.
Now you want to configure the events for the two rework outcomes (Resubmitted and Canceled). First, you will route the resubmitted outcome back to the Set Status Submitted event so that the workflow returns to a previous step in the workflow. For the canceled outcome, you will copy and paste a Set Status event, then update the Request Status value so that it indicates the request was canceled.
Notice now that K2 routes the Resubmitted outcome back to the Set Status Submitted event. This will create a loop effect in the workflow between the rework and resubmitted outcomes until a different action is selected.
You are removing this outcome because you don't need to continue the workflow after this step. If the decision is to cancel the request, then after the request status has been updated, the workflow will be complete.
STEP 6 REVIEW
In this step you added a third action for the manager approval task. You customized the task notification email so that the manager can use SmartActions to action the task directly from the email. You added a user task for the form originator in the event the manager decides the request needs to be reworked. You routed the resubmitted outcome so that the workflow essentially starts over again if the originator resubmits the request. Finally, you added a system event to update the request status if the originator decides to cancel the request.
In this step, you will explore escalations and how you can use them to keep your workflows running smoothly and in a timely manner. An escalation kicks in when a user has not responded to a task assigned to them within a specified time period. An escalation can be as simple as an email reminder or more complex, such as automatically redirecting the workflow to another user. Escalations can be set up to repeat themselves (for example, an email reminder every two days) and they can have repeat limits applied (such as send two email reminders, then redirect to another user).
In this step, you will apply an escalation to the manager approval user task that will send a reminder email to both the manager and the form originator if the manager has not responded within two days of the Leave Start Date.
Step 7 Tasks
- Add a new escalation to the manager approval event and name it
Manager Approval Reminder
then keep the default E-mail escalation type. - Select the Escalate On option then using the Inline Functions to subtract two days from the Leave Start Date value.
- Configure the email notification to be sent to both the manager and the form originator. Use properties from the context browser to customize the message.
- Click the Manager Approval event to highlight it. Right-click and select Escalations.
- When the Add Escalation screen opens, click Add.
- On the Escalation Settings screen, name the escalation
Manager Approval Reminder
then select the option Escalate On. - You want the escalation to fire 2 days before the leave start date. You will use an inline function to achieve this. In the context browser, expand the Inline Functions > Date and Time node and drag the AddDays function into the date field as shown below.
- On the AddDays screen, expand Item References in the context browser and drag the Leave Start Date property into the Date and Time field. For the Days value, enter (minus 2)
-2
then click OK, then click Next. - On the Escalation E-mail screen, CHECK the boxes to send the notification to the participant and the originator. This will send the email to the manager and the form originator. See the screen shot below for guidance, if needed.
For the subject line, enter
REMINDER: Leave Request for [Originator Name]
then expand the workflow context node in the context browser and drag the Originator Full Name into the subject line (replacing the bracketed text above).
For the message body, enter the following (again replacing the bracketed text with item references).
This is a reminder that the Leave Request [Leave Request Title] starting on [Leave Start Date] has not yet been approved. Please check your worklist items and process this request with your decision. - Your screen should look like the image below. Click OK to close the Activity Escalations screen.
- Save your work.
Here, you are simply telling K2 that you want to kick off this escalation two days prior to the Leave Start Date.
Click Finish when you are done to complete the Escalation wizard screen.
STEP 7 REVIEW
In this step, you added an escalation to send an email reminder two days prior to the leave start date in the event the manager has not actioned the request yet. You customized the email to include details about the specific request and configured the email to route to the manager and the form originator.
Before the workflow changes will be applied, you must deploy the workflow to the K2 server. Deploying a workflow publishes it and makes the current version available to your users. You must redeploy your workflow each time you makes changes.
Step 8 Tasks
- Deploy the workflow.
- Deploy the workflow (File > Deploy)
Now that the workflow changes have been published, you need to make a couple of tweaks to the forms used by the workflow, because you want the forms to behave differently depending on the current task. Recall in a previous step you added the Approver Comments field to the Leave Request item view and made it read-only by default. In this step, you will edit a rule to enable the comments field for the manager approval task. To do this, you will edit a rule on the Workflow Task state.
Step 9 Tasks
- Check out and then edit the Leave Request Form
- Edit the Form Initializing rule for the Workflow Task state.
- In the if current Workflow Activity is Manager Approvalcondition, add an action to set a View control's properties on the Leave Request item view that enables the Approver Comments Text Area.
- In K2 Designer, right-click the Leave Request Form and check it out (if it is not already), then Edit it.
- Click the Rules tab in the Breadcrumb Bar. (A below) Highlight the Workflow Task state, then highlight the When the Form is Initializing rule. Click Edit Rule. (Once again, the Workflow Task state represents the form and view configuration that the approving manager will see.)
-
Rules: Events, Conditions and Actions
As a reminder, rules consist of events, conditions and actions.- Events are when something occurs, such as clicking a button or when the form or view loads.
- Conditions evaluate if a criteria has been met: if the condition is true, continue. For example, evaluating a required field to determine if the field contains a value.
- Actions do something. If the event and condition passes, then perform the action, such as starting a workflow, or calling another rule, or enabling a form field.
- Confirm the Actions tab is highlighted. (A below) Click on the current action (then open the Manager Approval worklist item) to highlight it. In the Actions pane, scroll down until you see the Control Interaction heading. Click on the Set a View control's properties action to add it to the Workflow Activity condition, just below the open worklist item action as shown below.
- Click the select View link and select Leave Request Item View. Click the select control link and select Approver Comments Text Area.
- Click the (configure) link. On the Mapping Destinations screen, scroll down until you can see the General heading. Change the Read-Only setting from Yes to No. By turning off the read-only setting, the manager will be able to add comments when they open the form. Click OK. Click OK to return to the Rules home screen.
In the Rule Definition pane, locate the condition that says if current Workflow Activity is Manager Approval. Notice that this condition already has an action to open the Manager Approval worklist item. K2 added this condition and action when you configured the Manager Approval user task. You want to add an action at this point to enable the Approver Comments field.
STEP 9 REVIEW
In Step 9, you edited the Workflow Task state, Form Initializing rule and enabled the Approver Comments field for the Manager Approval task. This will allow the approving manager to add comments to the request if they choose. This step demonstrated the power of states and how you can edit individual states to customize the form and view configurations for a specific task or event.
Now you will add a new rule to this state. This rule will allow you to save any changes the manager might have made to the form, such as adding approver comments. (Save is the equivalent of update. When adding a new record, the Create method is used.)
Step 10 Tasks
- Add a new rule to the Workflow Task state. Add the event After the Workflow action was submitted.
- Add a Execute a View method action to call the Save method of the Leave Request item view.
- You may Auto-Map the Input Properties, but you MUST delete the auto-mapped ID value and replace it with the Leave Request Item View SmartObject ID property so that K2 knows you are referencing the current record.
- On the Rules home screen, confirm the Workflow Task state is highlighted, then click Add Rule.
- Click the Events tab. (A below) Scroll down until you see the Workflow Events heading. Locate and click the After the Workflow action was submitted event to add it to the Rule Definition pane.
- Now click the Actions tab and click to add the Execute a View method action to the Rule Definition pane. Click the select View link and select Leave Request Item View. Click the select method link and select Save.
- Click the (configure) link. Click Auto-Map. (In some versions of K2 blackpearl, the ID property may be auto-mapped as well. Continue to the next step on editing the ID property.)
- If there is an auto-mapped ID, click to the right of the ID value and backspace until you have removed it. With the field empty, expand the Leave Request Item View in the Context Browser, then expand the Leave Request SmartObject. Drag the SmartObject ID into the Input Properties > ID field.
If the ID property has a value, you need to replace it with the correct SmartObject ID. If the ID property was left empty, you need to map the SmartObject ID to it.
Click Finish. Click OK to close the Rule Designer.
STEP 10 REVIEW
In this step, you added a rule that will fire off the save method (which is the equivalent of update) for the Leave Request SmartObject with any changes the approving manager might have made.
The last few edits you are going to make to the rules will be to clear the form entries after the form originator has clicked the Create button, then add the new entry to the list view. (The list view contains all of previous leave requests.) Recall in the basic tutorial, when the form originator submitted the form there wasn't any visual indication of the form being submitted. By clearing the form entries and updating the list view, the user will have visual confirmation that their request was submitted.
Step 11 Tasks
- Edit the rule for the Leave Request Workflow (Default) state, when the Create Button is clicked. Add a View method action to Clear the Leave Request item view.
- Add another View method action to populate (Get List) the Leave Request list view, using the System Value Email as the Input Property.
- Add a Transfer data action and map the Current User Display Name and Email to their respective form controls.
- Check In the Leave Request Form.
- First you will configure an action to clear the form entries upon submit. On the Rules home screen, highlight the Leave Request Workflow (Default) state, then the Create Button is Clicked rule. (The Leave Request Workflow (Default) state is the configuration for the form originator.) Click Edit Rule.
- Confirm the Actions tab is highlighted, then click the Execute a View method action to add it to the Rule Definition pane. Click the select View link and select Leave Request Item View. Click the select method link and select Clear.
- Click Execute a View method once again to add another instance to the Rule Definition pane. Click the select View link and select Leave Request List View. Click the select method link and select Get List. Click the (configure) link.
- In this step, you will map the current user's email as the input property so that K2 knows to search the SmartBox records for those that have the same email value as the current user. In the context browser, expand System Values, then Current User and drag the Email property into the Employee Email Input Property. Click Finish.
- Still on the Actions tab, search for
transfer
then click Transfer data to add it to the Rule Definition pane. Click the (configure) link. - In the context browser, expand the System Values node, then Current User. Drag the Display Name into the Employee Name Text Box field and the Email into the Employee Email Text Box field. Click OK twice, then click Finish to save and exit the form.
- Right-click the Leave Request Form and select Check In. If you get a message about associated Views, click OK to continue.
Sorting through events and actions: first you see an event for when the Create Button is Clicked. Then the Create method for the SmartObject fires and creates the record in the Leave Request SmartBox SmartObject. Then the workflow starts. Finally the Leave Request Item View is cleared.
Now you will update the Leave Request list view so that the new entry is displayed.
You have one additional step you need before you close out of your form. In the previous step, you cleared the form entries when the user clicked the Create button. Now you need to add back in the Employee Name and Employee Email values so the refreshed form appears exactly the same as a brand new form. Recall that you configured the Employee Name and Employee Email values to be the current user values, which you again, obtain from the context browser, system values.
STEP 11 REVIEW
In this final step of configuring actions, you added a clear method so that the user will have a visual confirmation that their form was submitted. There are a number of mechanisms for letting your users know they have successfully submitted a form, including adding a confirmation pop-up message or redirecting them to a web page, for example. As you build more applications within your own environment, you will gain knowledge of what works best for your target users.
Now that your application changes are done, you will move on to Part 4: Test, to try out your application!