How To: Modify a Workflow to Link an Application's Start Rule to a Secondary List or Library

You can reuse artifacts with other lists and libraries, as long as those other lists and libraries match the primary list or library's structure. To reuse a K2 for SharePoint application's workflow, use this article to modify your workflow to include parameters that allow the same workflow to be used in different (but matching) lists or libraries.

Note: The approach described here is only for a workflow which starts when a SmartForm is submitted. It does not apply to workflows started with an event in SharePoint, such as item/document added. See Reusing K2 for SharePoint Workflows for information on linking workflows that start with an event in SharePoint.

Scenario

You have regional staff employee lists (Employees_US, Employees_EU, and Employees_APAC) in SharePoint, the data structure of the lists is the same, and they are on the same SharePoint web application. You appify a primary list (Employees_US) with SmartObjects, SmartForms, and a workflow, and then reuse the SmartForms and workflow with your secondary lists (Employees_EU and Employees_APAC). See How To: Create a SmartForm to Link an Application's SmartForms to a Secondary List or Library .

Steps

You first create your SharePoint matching lists, then create a K2 application using the primary list, creating SmartForms and a workflow. You then modify your workflow to include the Site URL, List ID, and Item ID parameters and recreate item references. Finally, you update the SmartForm's start rule to use those parameters.

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 Modify the Workflow to use the K2 for SharePoint Reuse Parameters.

  1. Create two matching SharePoint lists
    1. In SharePoint, create a custom list for the Employees of the USA region.
    2. Name the List Employees_US
    3. Create the following columns
      • Title, using column type Text
      • Name, using column type Text
      • Address, using column type Text
      • Phone, using column type Number
    4. Create another custom list for employees of the European Union region
    5. Name the List Employees_EU
    6. Create the same columns as you did in the Employees_US list
  2. Appify your primary list. This creates the artifacts to reuse.
    1. For your Employees_US list, select the K2 Application icon from the list menu bar
    2. Select the Create SmartForms option on the Create K2 Application page
    3. Keep the default selection of Use K2 smartforms as the New, Edit, and Display forms for this list/library option
    4. Select the Create Workflow option
    5. Keep the default selection of Specify how the workflow gets started > When a SmartForm is submitted > Form: New Employees_US
    6. Click OK to finish creating the K2 application
    7. The system creates SmartObjects, views, and forms for the list, then opens the Designer for you to design your workflow.

Modify the Workflow to use the K2 for SharePoint Reuse Parameters

To reuse your workflow, replace the existing K2 for SharePoint application SmartObject Item References in the workflow with a new reference containing the Site URL and List ID parameters. Then modify the start rule of the SmartForm to use the new parameters.

  1. Configure your workflow start event with default options. Take note of the SmartForm and rule action
    1. Expand the start event and click the Edit link in the How will this workflow be started? section
    2. Keep the default selections, but make a note of the SmartForm, action and rule , which you will be editing
  2. Remove the existing item references
    1. Expand the Context Browser
    2. Right click the Employees_US item reference and select Delete
    3. Do the same for Employees_US Attachments item reference
  3. Add three variables for the Site URL, List ID, and Item ID parameters. You use these in the new item references and in the SmartForm start rule
    1. In the Context Browser click the Add link in the variables area
    2. Add Text variables for Site URL, List ID, and Item ID
  4. Create and configure a reference event for the Employees_US SmartObject. The original reference did not have the Site URL and List ID parameters
    1. Drag a Create Reference step from the basic steps onto the design canvas
    2. Click the SmartObject drop down and navigate to your SharePoint folder and select Employees_US
    3. Select the Get List Item By ID method
    4. Add Site URL and List ID input properties
      [to do]
    5. Drag the Item ID, List ID, and Site URL variables from the context browser into the matching input mappings
    6. Click the output mappings Create
    7. The Employees_US reference is created
  5. Create a second reference event, this time for the Employees_US Attachments SmartObject
    1. Drag a Create Reference step from the basic steps onto the design canvas
    2. Click the SmartObject drop down and navigate to your SharePoint folder and select Employees_US Attachments
    3. Select the Get Attachments method
    4. Add Site URL and List ID input properties, then remove the Name (LinkFilename) property (as the Item ID is used for identity)
    5. Drag the Item ID, List ID, and Site URL variables from the context browser into the matching input mappings
    6. Click the output mappings Create to create the Employees_US Attachment reference
  6. You have configured this workflow with the K2 for SharePoint artifact reuse parameters. Add a Send Email step to complete the workflow.
    1. Drag an email step onto the design canvas
    2. Configure the step with the following details
    3. Deploy the workflow
  7. Update the SmartForm rule that you took note of in Step 3 to use the data fields from the workflow instead of the item references you deleted.
    1. Locate and edit the New Employees_US form.
    2. Select the Rules tab of the SmartForm. Note the red exclamation mark
    3. Select New Employees_US > On New Emplyoees_US, when Save Button is Clicked
    4. Locate the then start the ... Workflow action and click configure
    5. Deselect the previously-configured item references
    6. Drag the ID field from the Employees_US SmartObject in the context browser to the Item ID workflow data field
    7. Drag the List parameter from the New Employees_US view to the List ID workflow data field
    8. Drag the RootWebUrl and SubsiteRelativeUrl parameters to the Site URL workflow data field. These two parameters form the full Site URL
    9. Click Finish to save your changes
    10. Check the form in

    You can now link the SmartForm to a secondary list or library. See Reuse K2 for SharePoint SmartForms for further information and the steps to create those links. Once the SmartForm is linked, adding a new item starts the workflow.

Review

In this article you modified your K2 for SharePoint application workflow to use the Site URL and List ID reuse parameters and updated the When the form is submitted rule of the SmartObject to use the parameters.