3. Test, Rename, and Move the New SmartObject

In this step, you will test the new SmartObject to confirm the connection settings. You will test the SmartObject from the K2 Management site by executing the list method. You should see a list of leave types returned.

You will also move the new SmartObject to your Leave Request category. When you generated the SmartObject as part of the new service instance configuration, K2 automatically created a new category called SQL Server Service and placed the new SmartObject in that category. You want to move the SmartObject to the Leave Request > SmartObjects category so all your application artifacts are in one location.

  1. Expand the Categories > SQL Server Service node. Locate the [HumanResources].[LeaveType] table under the Leave Types service instance. Many of these same categories also appear in K2 Designer. For example, notice the K2 Learning category. This is the same category you have been working with in K2 Designer.
    Locating the Leave Types SmartObject in the Categories Menu
    1. In this step, you will locate, then test, the SmartObject that K2 generated as part of the new service instance configuration. You will test the SmartObject by executing the list method and confirming you see a list of leave types returned.
      Expand the Categories node, then expand the SQL Server Service node. Notice the Leave Types node. Expand Leave Types, then Tables. K2 discovered six tables with this SmartObject, along with several some SQL views.
    2. When you generate SmartObjects from the service instance, K2 returns all the tables and views it discovers as SmartObjects. K2 names the SmartObjects according to their data source schema. In this step, you will be working with the [HumanResources].[LeaveType] table.

    3. Now, you are going to execute the list method on this SmartObject to confirm the connection settings are correct. Click the [HumanResources].[LeaveType] table to expose the properties and methods in the central pane. Take a minute to review the following sections:
      • A: Displays the system details such as the system name, date created and created by values.
      • B: Displays the properties: LeaveTypeDescription and LeaveTypeid (think spreadsheet column titles).
      • C: Displays the methods for this table. You will use the List method to return a list of leave types for the Leave Type drop-down list on the item view. Put simply, methods are how K2 interacts with data: create, save, delete, load, list.

  2. Execute the List method. Confirm results are returned with two properties shown: LeaveTypeid and LeaveTypeDescription. You do not need to enter any input properties, just let K2 return all the results it finds.
    1. Next, you will test the SmartObject connection by executing the list method. The list method returns a list of all the records found in the data source. You can enter input properties to filter the results if necessary, but for this test, you will return all records.
      In the Methods pane, click to highlight the List method, then click Execute.
    2. There are no input properties for this test, so click Execute once again. The Results pane appears with the values from the [HumanResources].[LeaveType] table. This confirms the external SQL database connection is correct. Click Done to exit the Execute SmartObject Method screen.
  3. Next, you will move the SmartObject so that it resides in the Leave Request category. Then, you will rename the SmartObject to a friendly name. With the SmartObject highlighted, click the Design link to launch K2 Designer. Edit the SmartObject. From the GENERAL properties tab, move the SmartObject to the Leave Request > SmartObject category. Rename it Leave Types.
    Move a SmartObject
    1. The last steps in this series are to move and rename the new SmartObject to the Leave Request category. This will keep all your K2 artifacts organized and easy to locate as you move through the next tutorials.
      First you will move the SmartObject to the Leave Request category. Select the [HumanResources].[LeaveType] SmartObject. Click the Designlink in the upper right corner of the central pane.
    2. K2 Designer launches. With the SmartObject still selected, click the Edit link in the central pane.
    3. Switch to the GENERAL settings screen. Change the Name of the SmartObject to
      Leave Types
      then change the category to the Leave Request > SmartObjects category.
    4. Click FINISH to republish the SmartObject. Remember, finishing a SmartObject publishes that version of the SmartObject to the K2 server.
      Changing a SmartObject Name; Moving a SmartObject
    5. Switch back to the Management tab in your browser. Right-click the Categories name and select Refresh Menu. Expand the K2 Learning > Leave Request > SmartObjects categories and confirm the Leave Types SmartObject is shown. Notice too, that the Leave Request SmartObject also appears in Management site menu. This is the SmartBox SmartObject you created in the basic tutorial.
Review

In this step, you tested the new SmartObject configuration, renamed the SmartObject, then moved it to a new category. You tested the SmartObject by executing the list method. If successful, you should have seen a list of leave types returned. You changed the name of the SmartObject and moved it to the Leave Request category to keep your application organized.

Next Step: 4. Add the Approver Comments Control to the Leave Request Item View and Bind the Leave Type Drop-Down List