Use Case

Why create a custom actions section? Sometimes you'll need a more dynamic way to action user tasks from your forms in order to integrate more seamlessly with your workflow. The default actions section is great in a review process, but often you may find that you need more information from your users. In this scenario, we'll use a leave request process that will require comments from the administrator on review of the submitted request. Here are a few ways the submit section can help your user experience:

  • Validation on submit action
  • Requiring information from the user
  • redirect/close form after submit
  • Capture user comments history
  • Customize Actions UI

This how-to uses the Leave Request Accelerator as the starting point. To find out more about using the Accelerators in your solution, use this link: http://help.k2.com/onlinehelp/k2appit/UserGuide/current/default.htm#App_Templates/App_Templates.htm

Creating a Comments History List

In this portion of the How-To, a comments list will be created to capture the user comments throughout the workflow. This both organizes and creates a history of the comments added.

  1. From your SharePoint site, select add an app, then create a new Custom List and name it Workflow Comments.
  2. From the site contents, select the newly created Workflow Comments to open the list.
  3. Once in the View, open the List tab at the top, and select List Settings.
  4. Scroll down to the Columns and click Create column to create a new column called Comments by using the settings below. Click OK when you are done.

    Column Name

    Comments by

    Type of Information

    Person or Group

    Require that the column contains Information

    No

    Enforce Unique Values

    No

    Allow multiple selections

    No

    Allow selection of

    People Only

  5. Create a new column called Comments using the following settings. Click OK when you have finished.
     

    Column Name

    Comments

    Type of Information

    Multiple lines of text

    Require that the column contains Information

    No

    Number of line for editing

    6

    Type of text

    Plain text

    Append Change to Existing Text

    No

  6. Create a new column called Date using the following settings. Click OK when you have finished.
     

    Column Name

    Date

    Type of Information

    Date and Time

    Require that the column contains Information

    No

    Enforce Unique Values

    No

    Date and Time Format

    Date Only

    Display Format

    Standard

    Default value

    None.

  7. Create a new column called Form ID using the following settings. Click OK when you have finished.

    Column Name

    Form ID

    Type of Information

    Single line of text

    Require that the column contains Information

    No

    Enforce Unique Values

    No

    Max characters

    255

    Default value

    None.

  8. Now that we have added the columns we will use, open the Advanced settings of the list.
  9. Change the Attachments setting to Disabled and select OK at the bottom of the form. A warning will be generated for turning off the attachments. Select OK to commit the changes.
  10. Click the Workflow Comments text at the top of the form to return to the list view.

Now that the workflow comments list has been created, the next step is to create the views that will be used in the Leave Request forms to capture the comments, as well as display historical comments.

 

Creating the Views for Comments

In the Workflow Comments list, two Views will be created for use in the Leave Request. One view will allow users to add new comments, and the other will display existing comments.

  1. From the top ribbon, navigate to the K2 Application by selecting the Application Icon in the List tab at the top of the list.

    Image
  2. Select Create New Application.
    Image
  3. Select the Data option, and change the dropdown to Site and all of its subsites and then select OK.
  4. Once the application has been created, select the New tab, and create a new View.
    Image
  5. Navigate to the General tab of the breadcrumb bar. Name the view New Comment, select Item View as the view type, and select Next.
    Image
  6.  Select Create Layout Table Only, and choose a 3 column 3 row layout.
  7. Select the top middle cell, and use the merge button to combine the top center, and top right cells.
    Image
  8. Select the center cell, and merge with the cell to the right. Your layout should look like this:
    Image
  9. Click the Comments field in the Fields task pane, and drag it into the top merged cell, then drag the Comments Label into the first cell.
    Image
  10. Click on the Controls tab and drag a Label control into the left-middle cell, and a Drop-Down List control into the center merged cell.
    Image
  11. Select the Label control. Rename the Label to Submit Option Label and change the text to Submit Option.
  12. Add 2 buttons to the bottom right cell. Select the first button and rename it Button Cancel with the text Cancel. Rename the second Button Submit with the text Submit.
  13. Select the bottom right cell, and align to the right using the alignment options in the Style Bar.
    Image
  14. Click Finish to save the View.   
  15. From the K2 application page, select New and View to create a new View.
  16. In the General tab of the breadcrumb bar, name the View Comments List and select List View as the view type. Deselect the option to call this method when the form loads. Then click Next.
    Image
  17. On the View Canvas select the Option to Create Labels and Controls.
  18. Select the Comments by (Value), Comments and Date fields and select OK.
  19.  Drag the columns to rearrange the order as seen below, and adjust column widths by dragging the edge of the columns.
    Image
  20. Select the Comments by (Value) column and in the Properties tab and the Header and change the Text to Comments by.
  21. Select Finish to save your work.

Adding the Views to the Form

Now that the Views have been created, they will need to be added to the leave Request and configured for Submit.

  1. Navigate back to the Leave Request Form, and open the K2 Application elements page for the Leave Request List.
  2. Right click the Edit Event View, and Check Out the View. Right click the Edit Event View again, and select Edit.
    Image
  3. Select the Save Button, and uncheck the Visible option in the Properties menu under General.
  4. Repeat step 3 for the Cancel Button. Click Finish to save your changes.
  5. Right click the Edit Event Form, and select Check Out. Then right click the Edit Event Form again and select Edit.
  6. From the K2 Designer menu, expand the Workflow Comments list, and drag the New Comment View onto the Form.
    Image
  7. In the Properties menu, deselect the Collapsible option.
  8. Select the New Comment View. In the Rules task pane, select Add to add a rule.
    Image
  9.  In the Events tab of the Rule designer, add the When a control on a View raises an event event to the Rule. Select the New Comment View, when the Button Submit is clicked.
    Image
  10. In the Conditions, add a condition for a control on a view does not contain a value, and select New Comments View and the Comments Text Area
    Image
  11. In the Actions, search for message and select Show a message.
    Image
  12. Click configure and configure with the following settings:
    Image
     

    Message Size

    Small

    Message Type

    Default

    Title

    Comments Required

    Heading

    Please enter submit comments

    Body

    Entry cannot be submitted without comments.

  13. Search for stop and add Stop rule execution to the rule. This will prevent further actions in the form from occurring.
    Image
  14.  Add another condition for a control on a View contains a value. This condition should be added below the stop rule execution action, in a different group. Select the New Comment View and Comment Text Area.  
    Image
  15. On the Actions tab, add a rule to Execute a View method. Select the New Comment View and the Create List Item method. Then click configure.
    Image
  16. Drag the Form ID from the Edit Event View, under the Leave Request SmartObject. Type Leave Request into the Title field.
    Image
  17. From the New Comment View, drag the Comments Text Area onto the Comments field.
    Image                                                              
  18. In the System Values, drag the Current user email into the Comments by and the Current date into the Date and click Finish.
    Image
  19.  Search for another, and add Execute another rule to the rules and configure, so that the On Edit Event, when Save Button is clicked is the chosen rule. Then select OK. Save your changes.
    Image
  20. At the top of the Form, click the Add Tab button to add a tab to your Form. Then use the folder next to the tab that was added to add one more tab. Name this tab COMMENTS.
    Image
    Image
  21. Drag the Comments List View onto the COMMENTS tab and deselect the Collapsible option in the Properties menu. Select the rules tab, and add a rule.
  22. Under the Form Events category, choose When a control on the Form raises an event, and select the COMMENTS tab as the control, and choose the is clicked as the trigger.
    Image
  23. In the actions, drag the Execute a View method action onto the rule. Select the Comments List View, and the Get List Items method. Then click configure.
    Image
  24. On the Input Properties, expand The Edit Event View, to the Leave Request SmartObject, and type Leave Request in the Title field and drag the ID onto the Form ID field. By using the title and ID fields, only related comments to the app and instance are returned, allowing the View to be used in other apps. Click Finish, and then OK to complete the rule.
  25. Save your changes and select Finish. Repeat steps 20-24 in the Display Form as well, to add visibility to comments.

Modifying the Workflow

  1. Right click the Leave Request Workflow and select Edit.
  2. Double click the Review Request step to edit the step.
    Image
  3. Select next twice to navigate to the User Form. Expand the form and select the Action settings
    Image
  4. In the actions settings, select Use an existing list control... and expand the Smartforms in the context browser and drag the Drop-Down List into the Select Control field and then click Next.
    Image
  5. In the Select Rule drop-down, select the On new Comment when Button Submit is clicked rule. Move the workflow start to below the Execution of the Save Button Rule. Then click Finish.
    Image
  6. Step through the remainder of the wizard and click Finish. Notice that the step is still set to the Originator for testing. The user assigned will need to be adjusted when ready to reflect the assigned to person in the workflow.
  7. Repeat steps 1-6 for Update Request and Secondary Review workflow steps.
  8. When finished, Deploy your workflow and test.