Start Forms and Task Forms (K2 Studio Workflow)

Watch Video

The behavior of Start Forms and Task Forms for Workflows was discussed in the 100.YYZ SmartForms Fundamentals course, but using a K2 Designer Workflow. Here we will apply the same concepts to a Workflow built in K2 Studio.

The integration between Forms and Workflows boils down to using Rules and Actions to start Workflows and open/complete Workflow tasks. When using SmartForms with Workflows, it is helpful to understand the relationship between the Workflow and the Form being used to interact with the Workflow. For example, you might use one Form to start a Workflow, but a completely different Form to open and complete a Workflow task. Or, you may want to use the same Form to both start the Workflow and complete a task in the Workflow, but use different States to determine whether the Form is starting the Workflow or completing a task.

There are separate Rule Actions to interact with Workflows, depending on what you want to do with the Rule. It is easiest to think in terms of Start Forms and Task Forms. Start Forms use a single Action to start a Workflow, while Task Forms use two Actions: one to open the worklist item based on a Serial Number when the Form is opened, and another Action to complete the task.

Start Forms

Start Forms use the Start a Workflow Action to start a Workflow. This Action is usually contained in a Rule for a button Click event or some other user-driven event. In the example below, the Start Workflow button’s Rule calls the Start Workflow Action to start the sample Workflow.

The Start Form is typically opened and completed by a user before the Workflow even exists: the Workflow is only started when the user takes some action on the Form. These Start Forms are usually “capture Forms” or “user input Forms” where the user will complete the Form with information before submitting the Form. In the majority of cases, the submit Action will save the data to some data store by calling a SmartObject method, and then start a Workflow in the same Rule. While these input Forms are normally purpose-built for Workflow, remember that you can re-use Views on the Form to save development time; you can also use Rule conditions to start Workflows based on some condition.

The Start Form would use a Rule calling the "Start a Workflow Action" to initiate the Workflow. As part of the configuration of this Action, you can set the Folio of the Process that will start, set any data fields in the Process, set the priority of the Process Instance, and the expected duration.

A Form Rule used to Start a Workflow

Task Forms

A Form used to complete a Workflow Task (also known as a worklist item) usually contains two Workflow-specific Actions: one Action opens the Workflow Task when the Form is initialized, and another Action completes the Workflow Task when the user takes an action on the Form. (Remember that Actions are contained in Rules, and these Rules would be configured to fire at the appropriate times.)

The first step is to open the associated task with the "Open a worklist item" Action, using the Serial Number to locate and open the Workflow Task. This Rule is usually executed when the Form is initialized, and would usually also read the available Actions for the task so that these can be presented to the user in some way, normally a drop-down menu. You can also read data from the Workflow Instance, like the Folio or data field values.

This next image shows that when the Form associated with the Approval step is opened, then open the worklist item for this task. When configuring this Rule, you will have to provide the Serial Number for the task: this Serial Number is a unique value that is usually passed as a Form parameter. We have highlighted the Serial Number in the screenshot below to show where it is usually found.

By default, opening a worklist item allocates the item to this user and they either need to complete the task or release it.


A Form Rule used to open a User Task worklist item

The second part is executed when the user wants to complete the task, normally with a button Click event. This part would use the "Action a Worklist Item" Action to complete the Workflow Task. You would normally pass the Action that the user selected through as part of the Action configuration so that the Workflow knows which way to go next. As part of the Action, you can also update the Process Folio and Process data field values.

The Action name used in the configuration for this step must exactly match the Action name defined in the Workflow, otherwise the Action will not complete successfully.

A Form Rule used to Action (complete) a User Task worklist item

Form States and Workflow integration

You should recall that Form States can be used to render the same Form in different ways depending on how the Form is being viewed. When you Workflow-enable a Form, Form States are used extensively, and usually the Form would have separate States for each step in the Workflow. For example, one State is used when the Form starts a Workflow, another State is used when the Form is used for a Client Event. Additional States are added for each of the Client Events that the Form is integrated with. This is very similar to the approach used in InfoPath Forms where different Views are used for different steps of the Workflow, but the difference is that with SmartForms, you do not have to define separate Views for each step. Instead, you will use different States for the same Form. K2 adds Rules for the States so that the Form can be rendered correctly based on the current activity.

States added and used by the Workflow wizards

You may want to define additional Rules on the Form and use the View Manipulation Actions we discussed earlier to control the Forms based on the current State. For example, you could use the “Disable a View” Action to prevent an approver from making changes to the data that was submitted for approval, but only if the Form State is equal to Approval. You will have to do this manually: K2 will not automatically disable the View for a user task because it does not know which fields you want to enable and which fields you want to disable.

Disabling a View after opening a Workflow Task

Summary

K2 smartforms3.1
Video Links Learn Support
No videos found for this article
K2 on YouTube
No Additional links found for this article
No self-learning content for this article
Try some scenarios...
No relevant support links available for this article