How To: Create a SmartForm to Link an Application's SmartForms to a Secondary List or Library

K2 for SharePoint allows you to reuse artifacts with matching lists and libraries. To reuse a K2 for SharePoint application's SmartForm, you execute a system SmartObject method to get the URL link properties of the primary list or library's SmartForms and then execute a second system SmartObject method to link them to the secondary list or library.

Using a SmartForm to execute SmartObject methods to reuse a K2 for SharePoint application's SmartForm

Scenario

You have regional staff employee lists (Employees_US, Employees_EU, and Employees_APAC) in SharePoint, and 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 and SmartForms, and then reuse the SmartForms to view data from your secondary lists (Employees_EU and Employees_APAC). 

You create a SmartForm that executes the system SmartObject methods that link a secondary SharePoint list or library to a primary list or library's SmartForms. You can link any standard primary K2 for SharePoint application SmartForm to a matching secondary list or library.

Steps

You first create your SharePoint matching lists, then appify your primary list, creating SmartObjects and SmartForms. The SmartObject methods that create the mapping between the primary list's SmartForms and the secondary list require the Site URL and List ID of both lists. You'll create a new SmartForm with four text box inputs and three storage parameters used to execute the SmartObject methods as detailed in Reuse K2 for SharePoint SmartForms. Once you create the rule to execute the SmartObject methods on the view and add it to a form, run the form to link the secondary list to the primary list's SmartForms.

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 the SmartForm to Link the Secondary List to the Primary List's SmartForms.

  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. In your European Union subsite (EU), 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. Click OK to finish creating the K2 application
    5. The system creates SmartObjects, views, and forms for the list
  3. Identify and store the Site URL and List ID values of your primary and secondary lists, as you'll use these in the SmartForm that links them.
    1. Click on your list's List Settings icon in the List menu
    2. On the List Settings page, copy the first portion of the URL as the Site URL. Include site and subsite values, such as https://sa-sp-current.denallix.com/HR/USA
    3. Copy the string at the end of the URL between =%7B and %7D as the List ID
    4. Do this for both Employee lists. Copy the values to a text file for later use in the form

Create the SmartForm to Link the Secondary List to the Primary List's SmartForms

You create a SmartForm that takes the Site URL and List ID of your primary list and executes a SmartObject method to get the New, Edit, and Display form URLs. It uses these values and the Site URL and List ID of your secondary list and runs another SmartObject method to link the SmartForms.

  1. Create the linking View
    1. In the Designer, click the Create - View option on the main page, or right-click a category and select New View. If you are not familiar with creating views, see How To: Create an Item View and a List View.
    2. Name the view LinkSPSmF_View
    3. Select a Category for the view
    4. Select Item View
    5. Click Create to start creating the view
    6. Click Create Layout Table Only
    7. Specify a table of two columns and three rows
  2. Add the Label, Text Box, and Button controls to the view. The text box controls hold the Site URL and List ID values for use in the rule that executes the SmartObject methods
    1. Drag a Label control from the Toolbox into the first cell of the table
    2. Specify PrimarySiteURL as the Name
    3. Specify Primary Site URL as the displayed Text
    4. Drag a Text Box control into the same cell as the label
    5. Specify PrimarySiteURL_Input as the Name
    6. Add a Label and Text Box in the cell below for the Primary Site ID
    7. Add Labels and Text Boxes in the cells of the second row for your Secondary Site URL and List ID
    8. Drag a Button control into the third cell of the first column
    9. Specify LinkSharePointList_Button as the Name
    10. Specify Link SharePoint List as the displayed Text
  3. Create the three parameters for storing the New, Edit, and Display form URLs
    1. Select the Parameters tab at the top of the view
    2. Add the following text parameters
      • New Form URL
      • Edit Form URL
      • Display Form URL
  4. Create the rule to execute the Get SharePoint List Forms URL SmartObject method. This SmartObject method gets the form URLs of the primary list's SmartForms.
    1. Select the Layout tab at the top of the View
    2. Select the Link SharePoint List button
    3. Click the Rules tab of the button control
    4. Click Add Rule
    5. Select the Actions tab in the Rule Designer
    6. Click Execute a SmartObject method from the Actions panel to add a new action
    7. Click select SmartObject on the new action, navigate to System > SharePoint 2013 Integration > SharePoint Integration Helper Methods
    8. Click OK
    9. Click select method in the rule
    10. Select Get SharePoint List Forms URL
    11. Click configure to assign inputs and returns for the SmartObject method
    12. Expand the Controls folder in the Context Browser and drag the text box controls for the primary Site URL and List ID into the Input Mappings. Use PrimarySiteURL_Input for the Site URL and PrimaryListID_Input for the List ID
    13. Click Next
    14. Drag the Return Properties from the Context Browser to the matching view Parameters
    15. Click Finish
  5. Create the rule to run the SharePoint List Forms URL SmartObject method. This SmartObject method creates the links from the primary list's SmartForms to the secondary list.
    1. Click Execute a SmartObject method from the Actions panel to add another action
    2. Click select SmartObject on the new rule, navigate to System > SharePoint 2013 Integration > SharePoint Integration Helper Methods
    3. Click OK
    4. Click select method in the rule
    5. Select Set SharePoint List Forms URL
    6. Click configure to assign inputs and returns for the SmartObject method
    7. Expand the Controls folder in the Context Browser and drag the text box controls for the secondary Site URL and List ID into the Input Mappings. Use SecondarySiteURL_Input for the Site URL and SecondaryListID_Input for the List ID
    8. Expand Parameters in the Context Browser and drag the parameters to their matching input properties
    9. Click Next
    10. Click Finish
  6. Add a notification. This creates a popup message to tell you that the SmartObject methods have been executed and the mapping is done
    1. Navigate to the Notifications node of the action rules
    2. Select Show a message from the Actions panel to add a notification message
    3. Click configure to create the popup message
    4. Specify Linking Notification as the Title
    5. Specify SharePoint SmartForms Linking as the Heading
    6. Specify "The SmartObject methods have completed and your primary list's SmartForms are linked to your secondary list." as the Body
    7. Click OK to end this rule definition
    8. Click OK to complete the button rules
    9. Click Finish to complete and save the View
  7. Create the form. This adds the view to a new form
    1. On the LinkSharePointSmartFormReuse_View page in the Designer, click Design a new Form
    2. Specify LinkSharePointSmartFormReuse_Form as the Name
    3. Specify "Creates the links between a primary SharePoint list's SmartForm and a secondary matching SharePoint list." as the Description
    4. Select a Category
    5. Click Create
    6. Click (Enter View Title)
    7. Specify SharePoint SmartForm Reuse as the title
    8. Click Finish to complete and save the Form
  8. Run the form, paste in the necessary Site URLs and List IDs, and then click the button to execute the SmartObject methods that create the link
    1. On the LinkSharePointSmartFormReuse_Form page in the Designer, click Run
    2. Specify LinkSharePointSmartFormReuse_Form as the Name
    3. Copy and paste the primary Site URL and List ID, and the secondary Site URL and List ID from the text file you created in Step 3 into the matching text boxes
    4. Click the Link SharePoint List button
    5. See the notification popup

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 SmartForms back to using SharePoint forms, you can appify your secondary list or libraries without resetting the form links. See Working with SharePoint 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.

Review

In this article you created a SmartForm that executes the system SmartObject methods that link a secondary SharePoint list to a primary list's SmartForms.