Introduction

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.

Implementation

The following SmartObject setup is required in K2 smartforms:


 Image

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

  1. Extend the Subject SmartObject by opening a K2 Designer for Visual Studio project and then navigate to the Object Browser.
  2. Locate the Subject SmartObject in the SmartObject Server, right-click the SmartObject and select Save to Local
  3. The Subject SmartObject is saved to the Solution Explorer

    Image

  4. Double click the Subject SmartObject to open it
  5. Click on Advanced in the top left corner to create an Advanced SmartObject
  6. Select to create a new Method, and check the option to run the wizard in Advanced mode

    Image

  7. Provide the method with a Name, and select the List method type

    Image

  8. Add a new Parameter which will be used to capture the ID of the Student

    Image

  9. Next we want to bind the Service Object Methods. For this example, we’ll use the GetList methods of the Course and Subject SmartObjects

    Image

  10. For the Subject SmartObject, select the Auto Map function

    Image

  11. For the Course SmartObject, select the Create All function

    Image

  12. For the Get List method of the Course SmartObject, bind the custom Input Parameter to the Student_ID_ForeignKey as shown below

    Image

  13. 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

    Image

  14. Finish the wizard, and re-deploy the SmartObject.
  15. Continue to the K2 smartforms Designer and create a new List View, using the Subject SmartObject as the data source of the View.
  16. In the List method drop down, select the above created method, and deselect the Call this method when the form loads option.

    Image

  17. Select to generate the layout of the View with the required fields, and continue to the Layout Page.
  18. 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.
  19. Add a new Rule to execute the custom method

    Image

  20. Click on configure next to the Action and map the Textbox control to the Input Parameter

    Image

  21. Finish the Rule and Save the View
  22. Test the scenario by creating a Student Item View, Course Item View and Subject Item View and capture data into the Views
  23. Then create a Student List View, Course List View and Subject List View
  24. 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
  25. 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

    Image