This Knowledge Base article describes how to extend K2 smartforms through K2 Designer for Visual Studio to enable filtering of complex data. We will use a SmartObject created in smartforms to add a new List method in K2 Designer for Visual Studio which will in turn be used in a smartforms Rule to enable filtering of the data.
The following SmartObject setup is required in K2 smartforms:
All three SmartObjects are standard SmartBox SmartObjects, each with its normal Create, Delete, Save, Load and GetList methods. Follow the steps below to implement the scenario as described above
- Extend the Subject SmartObject by opening a K2 Designer for Visual Studio project and then navigate to the Object Browser.
- Locate the Subject SmartObject in the SmartObject Server, right-click the SmartObject and select Save to Local
- The Subject SmartObject is saved to the Solution Explorer
- Double click the Subject SmartObject to open it
- Click on Advanced in the top left corner to create an Advanced SmartObject
- Select to create a new Method, and check the option to run the wizard in Advanced mode
- Provide the method with a Name, and select the List method type
- Add a new Parameter which will be used to capture the ID of the Student
- Next we want to bind the Service Object Methods. For this example, we’ll use the GetList methods of the Course and Subject SmartObjects
- For the Subject SmartObject, select the Auto Map function
- For the Course SmartObject, select the Create All function
- For the Get List method of the Course SmartObject, bind the custom Input Parameter to the Student_ID_ForeignKey as shown below
- Continue with the wizard and configure the Service Join on the two Service Objects. For this we’ll use both the above configure methods, starting with the GetList method of Course, and doing a join on the Course_ID_ForeignKey and Course_ID_PrimaryKey respectively
- Finish the wizard, and re-deploy the SmartObject.
- Continue to the K2 smartforms Designer and create a new List View, using the Subject SmartObject as the data source of the View.
- In the List method drop down, select the above created method, and deselect the Call this method when the form loads option.
- Select to generate the layout of the View with the required fields, and continue to the Layout Page.
- On the Layout Page add a Toolbar Button control and a Textbox control to the toolbar area of the View, and then continue to the Rules Page.
- Add a new Rule to execute the custom method
- Click on configure next to the Action and map the Textbox control to the Input Parameter
- Finish the Rule and Save the View
- Test the scenario by creating a Student Item View, Course Item View and Subject Item View and capture data into the Views
- Then create a Student List View, Course List View and Subject List View
- Add the List Views to a Student Form as shown below and drag the List View created in step 15 at the bottom of the Form
- Type a student number in the Text Box provided on the bottom View and click on the Toolbar Button. Note how the student’s courses and subjects are filtered