How To: Filter a Form with a Parameter from another Form
Form Parameters can be configured in the Form Designer and are used to parse data from one Form to another.
The following example will help explain Form parameters. The aim of the scenario is to have a Form containing a list of departments. One should be able to select a department by double clicking on the department, and a Form should then be displayed listing all employees that are in that specific department.
In order to achieve what is required above, the following need to be set up in K2 smartforms:
SmartObjects
- Employee
- Department
Association between the two SmartObjects
- Each [Employee] has a single [Department]
- Each [Department] can have many [Employee]s
In the example, we want to select a [Department] and see all the [Employees] of that Department. The following Views and Forms are required:
Views and Forms
- [Department List View], living on [Department Form]
- [Employee List View], living on [Employee Form]… (the [Employee Form] will contain a Form parameter of type [Number])
When clicking on a Department record item on the Department Form, we want to open the Employees Form and only employees in that department should be displayed in a subform. The following rules are required to get this result:
Rules
Configure rule on [Department Form]:
-
When a View [Department List View] executes a method [List Item Double Clicked]
-
Open a Form [Employee Form] in a subform
Configure rule on [Employee Form]:
-
When the Form executes [Initialize]
-
Execute a method [GetList] on the View [Employee List View]
Configuration
Following are images of the configuration of the above mentioned objects:
Employees SmartObject
Department SmartObject
Association between Employees SmartObject and Department SmartObject
Department Form containing Department List View
Employees Form containing Employees List View
Employees Form containing the Department ID parameter
Rule on the Department Form
Data mapping for the rule on the Department Form
Rule on the Employees Form. This rule is auto generated when using the auto generate function to create a Form. Add the Get List rule definition item as below:
Data mapping for the Get List rule on the Employees Form
Disable the GetList rule action of the Employees List executed Initialize rule on the Employees Form as this will cause data to be returned in error.
Runtime Experience
Capture data for the Department SmartObject and Employees SmartObject. Then open the Department Form in runtime. A list of departments will be displayed. To see the employees in the Call Centre department for example, double click the Call Centre record item.
A subform is opened and the Employees Form is displayed. The results on this Form only contain the Call Centre as we've configured it in design time. We can now see all the employees in the Call Centre department.