How To: Use a form parameter to filter data on another form

You can use a form parameter to pass data from one form to another. For example, you can use a form parameter to send the department ID of a department list to an employee list, to filter the information to only show employees in that department.

Employees listed by department filter

Scenario

Your company has three departments, Finance, Human Resources, and Sales. You want to create a list of your departments and when a form user double clicks on a department, they see a list of employees in that department.

Steps

You create two SmartObjects (Department and Employees) and editable list views for each of the SmartObjects. You create an association between the Department and Employees SmartObjects, so that you can select the department when adding employee data. You then create standard list views and forms of both SmartObjects. On the Department form, you configure a rule to transfer the department ID as a parameter on the Employee form. You configure a rule on the Employee form to filter employees according to the department ID. When you double-click a department, a subform opens that shows you the employees of that department.

Setup Steps

The following steps set up the scenario. If you want to skip the setup steps and view the topic step, go to Create SmartForms to display a list of departments and employees.

  1. Create the Employee SmartObject with ID, Name, Surname, and Department properties. If you are not familiar with creating a SmartBox SmartObject, see How To: Create A SmartBox SmartObject.
    1. In K2 Designer, click create SmartObject.
    2. Specify Employees as the SmartObject Name.
    3. Specify a Description, and select a Category. In this scenario the category is Denallix.
    4. Leave the Type as SmartObject.
    5. Click Create.
    6. In the SmartObject properties page, click Add.
    7. Add ID,Name, Surname, and Department properties, using the following image as a guide:
    8. Click Finish.
  2. Create the Department SmartObject with DepartmentID and Name properties.
    1. In K2 Designer click create SmartObject.
    2. Specify Department as the SmartObject Name.
    3. Specify a Description, and select a Category. In this scenario the category is Denallix.
    4. Leave the Type as SmartObject.
    5. Click Create.
    6. In the SmartObject properties page, select ID and click Edit.
    7. Change the Name to DepartmentID and click OK.
    8. Click Add.
    9. Add a Department Name property, as shown in the following image:
    10. Click Finish.
  3. Create an association between the Employees and Department SmartObjects, assigning the Employees > Department property to the Department > DepartmentID property. This association links a single department to more than one employee (a one-to-many relationship).
    1. In K2 Designer, browse to your Denallix category, right click the Employees SmartObject, and click Edit.
    2. Select the Associations tab, then click Add.
    3. Navigate to and select the Department SmartObject.
    4. Click Next.
    5. On the Association page make sure the associations are defined as shown in the image below:
    6. Click Next.
    7. On the Relationships page select the Department property and click Assign.
    8. Select DepartmentID from the drop down.
    9. Click OK.
    10. Click Finish.
    11. Click Finish to save and close the SmartObject.
  4. Add information to the Department and Employees SmartObjects by generating and running editable list views. If you are not familiar with creating views, see How To: Create an Item View and a List View.
    1. In K2 Designer, browse to your Denallix category and right click the Department SmartObject.
    2. Click Generate Views.
    3. Check the Editable List check box.
    4. Click OK.
    5. On the Department Editable List page click Run.
    6. Click Add, and add departments using the following image as a guide:
    7. Click Save.
    8. In K2 Designer, browse to your Denallix category and right click the Employees SmartObject.
    9. Click Generate Views.
    10. Check the Editable List check box.
    11. Click OK.
    12. On the Employees Editable List page click Run.
    13. Click Add, and add employee information using the following image as a guide:
    14. Click Save.

Create SmartForms to display a list of departments and employees.

The steps below show you how to create the views and forms to display the information, and then configure rules so that when you double-click a department the employees form loads, displaying the list of employees in that department.

  1. Generate list views of the Department and Employee SmartObjects.
    1. On the Department SmartObject page, click Generate a View.
    2. Check the List check box.
    3. Click OK.
    4. Select the Employees SmartObject.
    5. On the Employees SmartObject page click Generate a View.
    6. Check the List check box.
    7. Click OK.
  2. Generate forms of the Department and Employees SmartObjects. Then add a parameter to the Employees form. If you are not familiar with creating forms, see How To: Create a Form.
    1. Select the Department List view.
    2. On the Department List view page click Generate a Form.
    3. Specify Department Form as the Form Name, then select Save and edit the Form.
    4. Click OK.
    5. Click the form title and specify Department as the title.
    6. Click Finish.
    7. Select the Employees List view.
    8. On the Employees List view page click Generate a Form.
    9. Specify Employees Form as the Form Name, then select Save and edit the Form.
    10. Click OK.
    11. Click the form title and specify Employees as the title.
    12. Then select the Parameters tab and click Add Parameter.
    13. Specify DepartmentID as the form parameter name. This parameter is used to filter the information displayed in the Employees form.
    14. Click Finish.
  3. Add a rule to the Department Form to transfer the DepartmentID field to the parameter of the Employees form.
    1. In K2 Designer browse to and select the Department Form.
    2. On the Department Form page, click Edit.
    3. Select the Rules tab.
    4. Click Add Rule.
    5. Navigate to the View Method node and click When a View raises an event.
    6. Your new rule should match the following image:
    7. Click select method and select List item double click. This configures the form to perform an action when an item on the list view is double clicked.
    8. Next, configure the action. Click on the Actions tab.
    9. Navigate to the Subform Interaction node and click Open a subform.
    10. Your rule should now look like the following image:
    11. Click select Form.
    12. Navigate to your Denallix category and select the Employees Form.
    13. Click (configure).
    14. Select the Input Mapping tab.
    15. In the Context Browser expand the Department Form to the Department SmartObject within the Department List (Department Form > Department List > Department).
    16. Drag and drop the DepartmentID from the Department SmartObject into the DepartmentID form parameter.
    17. Click Finish.
    18. Your rule should look like the following image:
    19. Click OK.
    20. Your form rules should look like the following image:
    21. Click Finish to save and close the form.
  4. Add a rule to the Employees form to filter the returned results by Department.
    1. In K2 Designer browse to and select the Employment Form.
    2. On the Employees Form page click Edit.
    3. Select the Rules tab.
    4. Select the When the Form is Initializing rule in the Employees Form node and click Edit Rule.
    5. In the rule Actions tab navigate to SmartObject Interaction, and click Execute a View method.
    6. The rule should now look like the following image:
    7. Click select method, then select Get List
      .
    8. On the input mappings page expand the Employees Form > Parameters and drag and drop the DepartmentID to the matching DepartmentID input property.
    9. Click Finish.
    10. Your edited rule should look like the following image:
    11. Click OK.
    12. Click Finish to save and close the form.
  5. Test the Department and Employees form interactions.
    1. In K2 Designer, browse to a select the Department Form.
    2. Click Run.
    3. The form loads the list of departments. Double click the Finance department.
    4. The Employees Form loads, and displays the list of employees in the Finance department.
Review

You created two SmartObjects (Department and Employees) and editable list views for each of them. You created an association between the Department and Employees SmartObjects, so you could select the department when adding employee data. You then created standard list views and forms of both SmartObjects. On the Department form, you configured a rule to transfer the department ID as a parameter on the Employee form. You configured a rule on the Employee form to filter employees according to the department ID. Then you tested this functionality by double-clicking a department, and a subform opened showing the employees in that department.