How To: Use a SharePoint Reference to Conditionally Start a Workflow
This topic shows you how to use a SharePoint library reference to configure a rule which determines if a workflow should start. You use a Conditional Start Rule to define this logic, and the data comes from the document in a SharePoint library using the automatically-created reference. You configure the Conditional Start Rule on the Start step and build it using the Rules Designer.
This How To assumes that you are familiar with K2 for SharePoint.
Using a conditional start rule to start a workflow when a purchase order document is added to the wrong library
Scenario
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 the Finance department stores them. All other documents are stored in the General Documents library. Sometimes documents are uploaded to the wrong library, 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.
Steps
In this scenario, you begin by creating two SharePoint document libraries called Purchase Orders and General Documents. Then you create a workflow and configure the Conditional Start Rule to determine if the workflow starts. In this case, the workflow should start when a document (with the word purchase order in the Name field) is added to the General Document library.
Setup Steps
The following steps set up the scenario from start to finish. If you want to skip the setup steps and view the topic step, go to Create a workflow and configure the Conditional Start Rule.
- Create a SharePoint library called Purchase Orders. You use this library to add all purchase order-related documents.
- In SharePoint, create a document library called Purchase Orders.
- The document library shows as below.
- Example of library with some purchase order documents in it.
- In SharePoint, create a document library called Purchase Orders.
- Create a SharePoint library called General Documents. You use this library to add all other documents. This includes Word, Excel, PDFs and image files.
- In SharePoint, create a library called General Documents.
- The document library shows as below.
- Example of library with some documents in it.
- In SharePoint, create a library called General Documents.
Create a workflow and configure the Conditional Start Rule
The following steps describe how to create a workflow and configure the Conditional Start Rule on the Start step. In this step, you create and configure a workflow called Document Move. In this scenario, you want the workflow to start when Purchase Orders are added to the General Documents Library. You are not worried about the other types of documents, only Purchase Orders. The workflow starts only if the condition, set in the rule, is met. In this case, the workflow starts if the Name field contains the words Purchase Order.
-
[Create a workflow and configure the Conditional Start Rule]
- From the K2 Designer click New and select Workflow.
- Name this workflow Document Move and click Create.
- Select the Start step and click the toggle to expand the Configuration Panel. You can also double-click the step to expand the panel. Select the Start with a SharePoint List option.
- Browse and select the General Documents library. Click OK.
- The Start Workflow from a List/Library page shows. Click Next. You use these references in the conditional rule later on.
- In the List Triggers section, select the An Item was added option and click Next. Here you specify that the workflow should start when a document is added to the General Document library. You'll add the rule later to specify the document condition.
- The Almost Done page shows. This page contains all changes to the library. Click Save and Finish.
- On the Success page click OK.
- The start rule is configured. Starting the workflow when an item is added to the library creates a reference in the context browser.
- To view the reference, open the Context Browser and expand General Documents in the References section. You use this reference to configure the condition for the start rule.
- To configure the condition for the start rule, select Conditionally Start and click Edit Start Rule.
- The Start Rule shows in the Rules Designer.
- In this scenario, you need to specify that if a document (containing the word purchase order in the Name field) is added to the General Documents library, the workflow should start. To do this you use the Name reference. From the Context Browser locate the Name reference and drag it into the condition.
- Change the operator to Contains.
- Type Purchase Order as the value.
- For the THEN option select Start. If the Name contains Purchase Order the workflow starts. For the ELSE option select Don't Start.
- From the K2 Designer click New and select Workflow.
- Configure and complete the rest of the workflow. In this step you also deploy the workflow.
- From the Toolbox, click the Basic category and drag the Task step onto the canvas. In this step you add the task Actions. Select Yes and No. No further configuration is needed for this step.
For more information on the Task step, see Task step.
- From the Task step, click and drag a line to create a Placeholder step. Click on this placeholder to create the Decision step.
For more information on the Decision step, see Decision step.
- From the Toolbox, click the SharePoint category then the Document category and drag the Move Document step onto the canvas. Connect the step to the Yes task action. You use the Move Document step to specify what happens to the document. In this case, it is moved from the General Document library to the Purchase Order library. Configure the step as shown below.
For more information on the Move Document step see Move Document step.
- From the Toolbox, click the Logic category and drag the End step onto the canvas. Connect the step to the No task action. Drag another End step and connect this one to the Move Document step.
For more information on the End step, see End step.
- The final thing to do is to deploy your workflow. From the File menu select Deploy.
For more information on deploying a workflow, see Deploy a Workflow.
- From the Toolbox, click the Basic category and drag the Task step onto the canvas. In this step you add the task Actions. Select Yes and No. No further configuration is needed for this step.
- Test the solution. In this step you add a document to the General Documents library. The Conditional Start Rule evaluates the name of the document. If the name contains Purchase Order the workflow starts. If the name does not contain Purchase Order, the workflow does not start.
- For the first test, add a document called Purchase Order 003 to the General Documents library. Click new document.
- Click Choose File, browse to the document and click OK.
- The Purchase Order 003 document is added to the General Documents library.
- The conditional start rule evaluates the name of the document and because it contains the words Purchase Order the condition is met and the workflow starts. From K2 Management, locate the Document Move workflow and select the Instances tab. Notice that workflow has started.
- In this scenario a task is sent to a recipient. The recipient select the Yes action and the Purchase Order 003 document is moved from the General Documents library to the Purchase Orders library.
- For the second test, add a document called Invoice 003 to the General Documents library. Click new document.
- Click Choose File, browse to the document and click OK.
- The Invoice 003 document is added to the General Documents library.
- The conditional start rule evaluates the name of the document and, because it does not contain the words Purchase Order, the condition is not met and the workflow does not start. From K2 Management, locate the Document Move workflow and select the Instances tab. Notice that workflow is not started.
- For the first test, add a document called Purchase Order 003 to the General Documents library. Click new document.
Review
The Conditional Start Rule is logic that evaluates your data outside of the workflow and according to the outcome either starts the workflow or not. For more information see Conditional Stat Rule.