Reusing K2 for SharePoint Workflows

When you create an application from a SharePoint list or library, you create SmartObjects which are then used to create SmartForms, workflows, and reports if you choose those options.

If you create a workflow for your list or library, you can link it to other matching SharePoint lists or libraries. SharePoint workflows can start in two ways:

For example, if you have regional staff employee lists (Employees_USA, Employees_EU, and Employees_APAC), and the data structure of all lists are the same and are on the same SharePoint Web Application, you can appify a primary list (Employees_USA) with SmartObjects, SmartForms, and a workflow, and then reuse the same items for the other two lists.

Reusing primary list and library workflows for secondary lists and libraries

How you configure the reuse of your K2 for SharePoint application's workflow depends on how the workflow starts. If it starts when a SmartForm is submitted, then you modify the workflow's references and the SmartForm start rule. If it starts from a SharePoint event, you run a sequence of SmartObject methods to create the event links between the workflow and the secondary list or library.

Workflow starts when a SmartForm is submitted

To link a workflow that starts when a SmartForm is submitted, you configure your workflow and SmartForm to use the Site URL and List ID properties. To do this, you first remove the SharePoint list or library's item references from the workflow and create new item references and configure them to use the Site URL and List ID properties. You then re-configure the start rule of the form to use those Site URL and List ID properties. See How To: Modify a Workflow to link an application's start rule to a secondary list or library for a step-by-step example.

Workflow starts from SharePoint events

To link a workflow that starts from SharePoint events, you call a sequence of SmartObject methods to create the SharePoint event links and workflow links from the workflow to the secondary list or library.

Use the following sequence of SmartObject method calls to create the integration links:

  1. Create a Setting ID for the secondary list or library. The Setting ID binds the workflow and events together and is unique for each SharePoint list or library
    1. Get the primary workflow's Setting ID. Execute the System > SharePoint 2013 Integration > SharePoint Integration Setting's Get List method using the primary list or library's Site URL and List ID
    2. Create a Setting ID for the secondary list or library. Execute the SharePoint Integration Setting's Create method using returned values from the Get List method of your previous step. In addition to the required properties, also add values for the following properties:
      • CreateSmartObjects
      • CreateForms
      • CreateWorkflows
      • CreateStartForm
      • CreateEditForm
      • CreateDisplayForm
      • FormSubmitted
      • EventOccured
      • Manual
      • SmartObjectName
      • DocumentLibrary
      • FormResetVersion
  2. Add the SharePoint events to the secondary Setting ID. When you have more than one event you create a new event link for each one
    1. Get the primary workflow's SharePoint integration setting events. Execute the System > SharePoint 2013 Integration > SharePoint Integration Setting Events' Get List method using the primary list or library's Setting ID
    2. Create the linked SharePoint events for your secondary list or library. Execute the SharePoint Integration Setting Events' Create method using your secondary Setting ID and primary SharePoint Integration Event ID
  3. Create a new workflow registry using your secondary Setting ID
    1. Get the primary workflow's SharePoint integration workflow values. Execute the System > SharePoint 2013 Integration > SharePoint Integration Workflow's Get List method using the primary list or library's Setting ID
    2. Create your secondary list or library's workflow registry. Execute the System > SharePoint 2013 Integration > SharePoint Integration Workflow's Create method using the secondary Site URL, List ID, and Setting ID, and the WorkflowName, Status, StartType, SmartObjectName, and DocumentLibrary values from your previous Get List method results
  4. Bind the workflow events to the workflow registry using the secondary Setting ID
    1. Get the primary workflow's SharePoint integration workflow values. Execute the System > SharePoint 2013 Integration > SharePoint Integration Workflow Event's Get List method using the primary list or library's Setting ID
    2. Create your bindings from your secondary list or library to the workflow registry. Execute the System > SharePoint 2013 Integration > SharePoint Integration Workflow Event's Create method using the secondary Setting ID, and WorkflowId and Event from your previous Get List method results
  5. Register the SharePoint event workflow trigger. The SmartObject executed in this step is from your SharePoint service object.
    1. Get the primary workflow's SharePoint integration workflow values. Execute the SharePoint 2013 Integration > [your.SharePoint.site] > Management > Event Get Event Receivers method using the primary list or library's List ID
    2. Register your secondary list's event trigger. Execute the SharePoint 2013 Integration > [your.SharePoint.site] > Management > Event's Register Remote Event method using the secondary List ID, primary workflow events for the RemoteReceiverTypes (you can pass all the events together separated by a semi colon ';', such as 1111;10001;10002), and the RemoteEventRecieverURL value from the Get Event Receivers method from the previous step
  6. Register the events to the workflow
    1. Execute the System > SharePoint 2013 Integration > SharePoint Integration Workflow Helper Method's Register Remote SharePoint Events method using the secondary Site URL and List ID primary workflow events for the RemoteReceiverTypes (you can pass all the events together separated by a semi colon ';', such as 1111;10001;10002), and the RemoteEventRecieverURL value from the Get Event Receivers method from the previous step

See How To: Link a SharePoint application's workflow to a secondary list or library for a step-by-step example of adding these SmartObject method calls to a utility workflow to create the linking.

Resetting the workflow links

When you need to remove the reuse links, such as if your secondary list is no longer part of the same set of lists and is customized with new columns just for that region, you must reset the list. You can then appify it and it becomes its own solution not linked to other solutions.

For SmartForm links, run the ResetSharePointListFormsUrl method of the SharePoint.Integration.HelperMethods system SmartObject. Use the Site URL and List ID values of the secondary list or library you're resetting as inputs to the method.

For lists and libraries only appified with forms, if you change your primary list from using K2 forms back to using SharePoint forms, you can appify your secondary list or libraries without resetting the form links. See Forms for more information on using SharePoint forms.

For workflow links, run the RemoveSharePointDynamicWorkflowLinking method of the SharePoint.Integration.HelperMethods system SmartObject. Use the Site URL and List ID values of the secondary list or library you're resetting as inputs to the method.

Considerations

K2 Cloud