How To: Custom Actions Section with Comments Record
KB001724
PRODUCT
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.
- From your SharePoint site, select add an app, then create a new Custom List and name it Workflow Comments.
- From the site contents, select the newly created Workflow Comments to open the list.
- Once in the View, open the List tab at the top, and select List Settings.
- 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
- 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
- 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.
- 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.
- Now that we have added the columns we will use, open the Advanced settings of the list.
- 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.
- 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.
- From the top ribbon, navigate to the K2 Application by selecting the Application Icon in the List tab at the top of the list.
- Select Create New Application.
- Select the Data option, and change the dropdown to Site and all of its subsites and then select OK.
- Once the application has been created, select the New tab, and create a new View.
- Navigate to the General tab of the breadcrumb bar. Name the view New Comment, select Item View as the view type, and select Next.
- Select Create Layout Table Only, and choose a 3 column 3 row layout.
- Select the top middle cell, and use the merge button to combine the top center, and top right cells.
- Select the center cell, and merge with the cell to the right. Your layout should look like this:
- 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.
- 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.
- Select the Label control. Rename the Label to Submit Option Label and change the text to Submit Option.
- 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.
- Select the bottom right cell, and align to the right using the alignment options in the Style Bar.
- Click Finish to save the View.
- From the K2 application page, select New and View to create a new View.
- 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.
- On the View Canvas select the Option to Create Labels and Controls.
- Select the Comments by (Value), Comments and Date fields and select OK.
- Drag the columns to rearrange the order as seen below, and adjust column widths by dragging the edge of the columns.
- Select the Comments by (Value) column and in the Properties tab and the Header and change the Text to Comments by.
- 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.
- Navigate back to the Leave Request Form, and open the K2 Application elements page for the Leave Request List.
- Right click the Edit Event View, and Check Out the View. Right click the Edit Event View again, and select Edit.
- Select the Save Button, and uncheck the Visible option in the Properties menu under General.
- Repeat step 3 for the Cancel Button. Click Finish to save your changes.
- Right click the Edit Event Form, and select Check Out. Then right click the Edit Event Form again and select Edit.
- From the K2 Designer menu, expand the Workflow Comments list, and drag the New Comment View onto the Form.
- In the Properties menu, deselect the Collapsible option.
- Select the New Comment View. In the Rules task pane, select Add to add a rule.
- 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.
- 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.
- In the Actions, search for message and select Show a message.
- Click configure and configure with the following settings:
Message Size
Small
Message Type
Default
Title
Comments Required
Heading
Please enter submit comments
Body
Entry cannot be submitted without comments.
- Search for stop and add Stop rule execution to the rule. This will prevent further actions in the form from occurring.
- 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.
- 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.
- Drag the Form ID from the Edit Event View, under the Leave Request SmartObject. Type Leave Request into the Title field.
- From the New Comment View, drag the Comments Text Area onto the Comments field.
- In the System Values, drag the Current user email into the Comments by and the Current date into the Date and click Finish.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Save your changes and select Finish. Repeat steps 20-24 in the Display Form as well, to add visibility to comments.
Modifying the Workflow
- Right click the Leave Request Workflow and select Edit.
- Double click the Review Request step to edit the step.
- Select next twice to navigate to the User Form. Expand the form and select the Action settings.
- 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.
- 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.
- 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.
- Repeat steps 1-6 for Update Request and Secondary Review workflow steps.
- When finished, Deploy your workflow and test.