3. Create a new SmartObject from a Service Instance

In this step, you create a new SmartObject from the Leave Types service instance. You will add the properties discovered in the service instance, along with one method, List. The list method returns a list of leave types that you will use in your Leave Request Form.

  1. Return to K2 Designer. From the Leave Request > SmartObjects category, create a new SmartObject called Leave Types. Add the List method from the Leave Types service instance. Create new SmartObject properties for the LeaveTypeId and LeaveTypeDescription data source properties.
    1. In this step, you manually create a new SmartObject from the Leave Types service instance. Return to K2 Designer, then right-click the Leave Request > SmartObjects category and select New SmartObject.
    2. Name the SmartObject
      Leave Types
      then select Advanced SmartObject. Use the advanced option when creating SmartObjects from a service instance. Click Create.
      Advanced SmartObject
    3. Next, you will bind the SmartObject to the Leave Types service instance. Click the Methods tab. You want to add only one method, List. You will see there are many methods and you could add all of them if you needed. This is one advantage to creating your SmartObject manually - you can pick and choose the properties and methods you want. Click the Add button.
      Add Methods
    4. On the Select a ServiceObject Method screen, locate the Leave Types service instance. Expand the Leave Types node, then expand the Tables node. There are six tables in this particular database that are discovered when you created the service instance.
      Table Discovered
    5. Expand the [HumanResources].[LeaveType] table. Here, you see a list of all the methods discovered for this table. Click List, then click Next.
      Methods Discovered
    6. You are now on the Details screen. This screen gives you a description of what the List method does, and you can configure parameters if you need too. (Think of parameters as pre-set values the method requires to run. In this case, you do not need any parameters for the List method.) Click Next.
      Method Details
    7. You are now on the Inputs & Outputs screen. Notice the two values under the input section: LeaveTypeId and LeaveTypeDescription. These are the properties discovered in the data source. In other words, these are the columns in the [HumanResources].[LeaveType] table. You want to create matching properties in your new SmartObject. You are creating an association in your SmartObject properties to the corresponding properties in the data source. Select the LeaveTypeId row, then click Assign.
      Assign a Property
    8. You don't have an existing property to map in your new SmartObject, so you need to create a new one. Click the Create button. Notice how the new property name is matched with the existing service instance property name. Click OK, then click OK again.
      Create Property
    9. Repeat the steps above to create a new property for LeaveTypeDescription. You should now have both service instance properties bound to properties in your new SmartObject. You don't need to edit the return properties since you are just retrieving leave types. Click Next, then Finish to complete this method configuration.
      Bound Properties
    10. Your new Leave Types SmartObject has one method, List. Click Finish to save and exit the SmartObject.
      List Method
  2. Before moving on, execute the List method for the Leave Types SmartObject in the Management site. Confirm results are returned with two properties shown: LeaveTypeId and LeaveTypeDescription. You do not need to enter any input properties, just let it return all the results it finds.
    1. Next, you will test the SmartObject configuration by executing the list method. The list method returns 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.
      Return to the Management site. Expand the Leave Request > SmartObjects categories. You should see the two SmartObjects created for this application: Leave Request SmartObject and Leave Types. (You may need to right-click the category and refresh the menu if you don't see both SmartObjects.)
    2. Select the Leave Types SmartObject. The details open 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 column titles in a spreadsheet).

      • C: Displays the methods for this table. You should only see the List method as you only added it to the SmartObject configuration. The List method returns a list of leave types for the Leave Type drop-down list on the item view. Put simply, methods are how Nintex K2 interacts with data: create, save, delete, load, list.
        SmartObject Details

    3. In the Methods pane, select the List method, then click Execute.
    4. There are no input properties for this test, so click Execute once again. The Results pane appears with the values from the Leave Types SmartObject. Click Done to exit the Execute SmartObject Method screen.
Review

In this step, you created a new SmartObject based on the Leave Types service instance. You added the List method only, because you do not need the other methods for this application. You created properties in your new SmartObject that are bound to the properties in the service instance. Finally, you tested the new SmartObject configuration by executing the list method and confirming there were leave type results returned. In the next step, you add the new Approver Comments to the item view.

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