Conditional Start Rule
In K2 Workflow Designer, you use the Start step to configure how your workflow starts. You can select to start the workflow with a form, a SharePoint event, or from K2 Management. By default, workflows always start when triggered by these methods.
Sometimes you don't want a workflow to start unless it meets certain conditions. In these cases, you use a Conditional Start Rule which allows you to add conditions in a rule to either start or not start the workflow. The Conditional Start Rule evaluates data outside of the workflow and, based on the outcome, either starts the workflow or not.
Keep in mind that the Conditional Start Rule is not a Decision step. This rule cannot determine which path to follow within a workflow or who gets a Task. It only evaluates the condition you set and starts the workflow if the condition is met.
If your Conditional Start Rule is met (condition = true) the workflow starts. If the condition is not met (condition = false) the workflow does not start.
If you start a workflow from a SmartForm and the start condition is not met, a message is shown and nothing further happens. You can find an entry in the server logs stating “The process <name> was not started because the conditional start rule evaluated to false” to show that the workflow instance did not start. To find the server log go to <install drive>:\Program Files\K2\Host Server.
Here are some examples where you might want to use a conditional start rule:
- If employees have five or more leave days available to them, start the workflow.
- If the requested start date falls within the last two weeks of December, don't start the workflow. See the How To: Use SmartForm references to determine the outcome of a workflow Conditional Start Rule.
- If a client's account is past due, don't start the workflow.
- If the travel claim is more than $2000, start the workflow.
- If someone adds a document with a specific document name to a SharePoint Library, start the workflow. See the How To: Use SharePoint Library references to determine the outcome of a workflow Conditional Start Rule.
- If a custom field status on a list item changes from In Progress to Ready for Review, start the workflow.
See the following resources for more information:
- See How To: Use a SharePoint References to Conditionally Start a Workflow for an example of using a SharePoint library reference to configure a rule which determines if a workflow should start.
- See How To: Use a SmartForm Reference to Conditionally Start a Workflow for an example of using a SmartForm reference to configure a rule which determines if a workflow should start.
Example
An example use of the Conditional Start Rule is that you use SharePoint document libraries to store team documents. You have two libraries called General Documents and Purchase Orders. These two libraries are not integrated with K2 for SharePoint. Purchase orders are supposed to be stored in the Purchase Orders library where Finance keeps them. All other documents are stored in the General Documents library. Sometimes documents end up in the wrong place, with purchase orders stored in the General Document library. In these cases, someone should be notified that documents are in the wrong library.
For this scenario, you want a workflow to start when Purchase Orders are added to the General Documents library. You are not concerned about the other types of documents, just Purchase Orders. The workflow only starts if the condition, set in the rule, is met. In this case, the workflow starts if the Name field contains the words “Purchase Order”.
To configure the rule, select the Conditional Start option in the Start step. You can use information from SmartObjects, references, and variables to configure the rule. You create an IF-THEN-ELSE rule using the Rules Designer.
From the Context Browser, drag Fields, Functions, SmartObject, or Workflow-related properties to customize the conditional start rule.
Example of a Conditional Start Rule- Select the Start step and click the expand / collapse toggle to expand the Configuration Panel. You can also double click the step to expand the panel. With the step selected, click the Start tab. In the Under what conditions should this workflow be started? section, the two available options are Always Start (default) and Conditionally Start.
- Select the Conditionally Start option and click Edit Start Rule. The warning badge indicates that you need to configure the rule.
- The Start Rule shows in the rules designer.
- Expand the Context Browser. Drag Functions,
Fields,
SmartObjects or
Workflow-related properties to customize the conditional start rule.
- To add additional conditions, click and drag a Conditions from the Rules Toolbar into the IF block.
- To change the operators, click the = sign and select one from the menu.
- To remove a condition, select it and click the Trash Bin.
- To add another IF/THEN condition, drag one from the Rules Toolbar into the THEN or ELSE block.
For more information on the rules designer, see Rules Designer.
When configuring a Conditional Start Rule, keep in mind the following:
- You may want to use an alternative mechanism in your solution, such as the following:
- Use the Decision step to send a workflow to the End step if a certain outcome is true.
- Define a SmartForm conditional rule to make a decision in a SmartForm rule to start the workflow or not, and then show a custom message based on the logic.
- If you need to determine if a workflow instance started or not, see the entry in the server logs. To find the log go to <install drive>:\Program Files\K2\Host Server.
- You can configure a Conditional Start Rule in workflows you created in previous versions of K2 Cloud. To do this, add the rule to the workflow and re-deploy it.
- After you edit or make changes to the Conditional Start Rule, remember to always re-deploy your workflow.
- If your workflow starts with a Form or a SharePoint event, and you edit your Conditional Start Rule, make sure to check the Form rules after you re-deploy the workflow. Editing the Conditional Start Rule may cause broken dependencies.
- If you deployed a solution to your environment that contains a workflow with a configured Conditional Start Rule, it is recommended that you open the workflow and check the dependencies are correct and working as expected.