How to: Use a form parameter to filter data on another form
Use the steps in this topic to create a form parameter to pass data from one form to another form.
The solution used in this example shows a list of departments. When you double-click a department, a subform opens that shows you the employees of that department. You create two SmartObjects (Department and Employees) as well as editable and standard list views for each of the SmartObjects. You also create forms for departments and employees. Each form contains a list view, and by setting up an association between the Department and Employees SmartObjects, you can add multiple employees per department.
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.
You use the Department and Employee editable list views to create departments and employees.
Runtime Example
Scenario
Your company has three departments, Finance, Human Resources and Sales. Each department has employees. Your Finance department has three employees (Bob, Blake and Anthony), Human Resources has two (Codi and Dennis), and the Sales department only has one (Ashley).
You want to see a list of the departments and, when you double click on a department, a form opens showing a list of employees in that department.
In this step, you create two SmartObjects - Employees and Department.
- From the K2 Designer, create the Employees SmartObject as shown below.
- Use the same steps to create the Department SmartObject.
In this step, you create an association between the Employees and Department SmartObjects.
- From the K2 Designer, right-click the Employees SmartObject and select Edit.
- Select the Associations tab and click the Add button.
- On the SmartObject tab of the Add Association page, browse to the Department SmartObject. Select it and click Next.
- On the Association tab, make sure the associations are defined as shown below. Click Next.
- On the Relationships tab, select Department and click the Assign button.
- On the Assign property page, select DepartmentID from the drop down and click OK.
- The Bound To field shows the association between Department and DepartmentID. Click Finish.
- Click Finish to close the Employees SmartObject.
In this step, you generate list views for the Department and Employees SmartObjects.
- From the K2 Designer, right-click the Department SmartObject and select Generate Views.
- On the Generate Options page, make sure that the list view is generated in the correct category. In this example, they are generated in the Views category. Check the List check box and then click OK.
- The generated list view show in the Views category.
- Use the same steps to generate a list view for the Employees SmartObject. Both list views show in the Views category.
In this step, you generate a form from the Department and Employees list views. You also add a number parameter to the Employees form.
- From the K2 Designer, locate and right click the Department List view. From the menu select Generate Forms.
- On the Generate Forms page, make sure the form is created in the correct category. In this example, it's created in the Forms category. Change the form name to Department Form. Click OK.
- From the K2 Designer, locate and right click Department Form and select Edit.
- On the Layout tab, change the Department Item view title to Department. Click Save.
- From the Properties tab, change the form theme to Lithium. Click Finish.
- Use the same steps to generate a form from the Employees list view. Call the form Employees Form and change the form title to Employees.
- On the Employees Form, select the Parameters tab and click Add Parameter.
- Add DepartmentID to the Name field and select Number as the Data Type. Click Finish.
In this step, you configure a rule on the Department form to transfer the DepartmentID field to the parameter of the Employees form.
- From the K2 Designer, right click the Department Form form and select Edit.
- Click the Rules tab and click Add Rule.
- Select the Events tab. Select the When a view raises an event.
- Click the select method link and select List item double click.
- On the Rule Designer page, select the Actions tab. In the search field type open a, locate the Subform Interaction section, and select Open a subform.
- Click select Form and browse to the Employees Form form. Click OK.
- Click the configure link. On the Open Employees Form as a Subform page, select Input Mappings. Expand the Department node in the Context Browser. Click and drag the DepartmentID property into the DepartmentID field. Click Finish.
- The rule shows as follows. Click OK to close the Rule Designer page.
- The configured rules are as follows. Click Finish.
In this step, you configure a rule on the Employees form to filter the return results.
- From the K2 Designer, right click the Employees Form form and select Edit.
- Click the Rules tab, select the When the Form is Initializing rule and click Edit Rule. This rule was generated when you selected the Generate Form option in Step 4 of this article.
- On the Rule Designer page, select the Actions tab. In the search field type method, locate the SmartObject Interaction section, and select Execute a View method.
- Click select method and select the Get List method.
- Click the configure link. On the On Employees List View, Execute the Get List Method page, select Input Mappings. Expand the Employees Form and the Parameters nodes in the Context Browser. Click and drag the DepartmentID property into the Department field. Click Finish.
- The rule shows as follows. Click OK to close the Rule Designer page.
- The configured rules show as follows. Click Finish.
In this step, you generate edit list views for the Department and Employees SmartObjects, and then add sample data to the Department and Employees SmartObjects using them.
- From the K2 Designer, right-click the Department SmartObject and select Generate Views.
- On the Generate Options page, ensure that the editable list view is generated in the correct category. In this example, they are generated in the Views category. Check the Editable List check boxes and then click OK.
- Use the same steps to generate the Employees editable list view. The views are located in the Views category.
- From the K2 Designer, locate the Department Editable List and click Run.
- Click the Add button and add data as shown below.
- Use the table below to add data to the Employees SmartObject.
Name Surname Department Bob Maggio Finance Blake Carrigan Finance Anthony Petro Finance Codi Kaji Human Resources Dennis Parker Human Resources Ashley Evans Sales - The completed Employees list view.
In this step, you run the Department Form and double click one of the departments. This opens the Employees Form showing all employees in that department.
- From the K2 Designer, locate the Department Form and click Run.
- On the Department form, double click the Human Resources department.
- The Employees Form loads showing the two employees in the Human Resources department.
- Click Close (X) to go back to the Department Form.
- On the Department Form double click the Sales department. The Employees Form loads showing the employee in the Sales department.
- The Employees Form loads showing the one employee in the Sales department.