5. Create the Expense Claim Line Item SmartBox SmartObject

In this step, you create a new data source that stores the "details" records, or expense claim line items. Recall that the Expense Claim list stores the "header" records. You will bind these two data sources via a common property (an ID) which creates a header-details, or parent-child record model.

SmartBox SmartObjects are K2-provided storage. K2 creates a table in the K2 database on your behalf. You can specify the properties (think columns in a table) along with the methods. Methods are the protocols you use to manipulate data (create, save, delete, etc.). Behind the scenes, K2 creates the programming and logic (code) necessary for connecting to and interacting with the SmartBox data source.
  1. From the K2 Application elements page, add a new SmartObject with the following configuration: (Once again, if you are working in a share environment where there may be multiple builds of this SmartObject, consider adding your initials so that the name is unique.)
    Field Value Notes
    NameExpense Claim Line Item  
    DescriptionStores line items for expense claims.  
    Category(leave default value unchanged)  
    TypeSmartObjectBasic SmartObjects automatically use the SmartBox database as their data store.
    Workflow Use (if shown)UNCHECKEDYou do not need to allow this SmartObject in workflows.
    1. From the K2 Application screen, click New, then select SmartObject.
      Add New SmartObject
    2. The K2 Designer opens on the GENERAL settings page. Configure the settings for the new SmartObject as follows, then click CREATE:
      Field Value Notes
      NameExpense Claim Line ItemOnce again, if you are working in a share environment where there may be multiple builds of this SmartObject, consider adding your initials so that the name is unique.  
      DescriptionStores line items for expense claims. 
      Category(leave default value unchanged)  
      TypeSmartObjectDefault SmartObjects automatically use the SmartBox database as their data store.
      Workflow Use (if shown)UNCHECKEDYou do not need to allow this SmartObject in workflows.

      SmartObject General Settings
  2. Add properties to the new SmartObject:
    Property Type Notes
    ID AutoNumber (Key) Unique ID for the line item.
    Expense Claim IDNumber
    (Required)
    Stores the ID of the associated Expense Claim Header SmartObject and is used to link line items back to their parent record. Mark this property as required.
    Category ID Number Stores the category ID for the expense item category. The category descriptions are provided by the SQL database you configured in a previous step.
    Payee Text Who the expense was paid to.
    Date Date The date of the expense.
    Description Memo A description for the expense line item.
    AmountDecimal The source amount for the expense claim (potentially in another currency).
    Currency Code Text The currency code for the expense amount.
    USD Amount Decimal The USD equivalent amount. This value will be calculated by the UI based on the date, amount and source currency values.
    Receipt Image An attached receipt for the expense.
    1. On the PROPERTIES screen, notice that K2 added an ID property as the key value. This ensures each record added to this SmartObject is unique with its own identifying ID.
    2. Now, you will add properties to the SmartObject. Click Add to add additional properties to the SmartObject using the following table as a guide. Click OK to continue.
      Property Type Notes
      Expense Claim ID Number
      (mark as required)
      Stores the ID of the header, or parent record. The Expense Claim list stores the parent record. K2 takes the ID of the parent record and passes it through to this record. This creates a bind between this record (the child) and the list record (the parent).
      Category ID Number Stores the Category ID for the expense item category.
      Payee Text The person receiving the claim reimbursement.
      Date Date The date of the expense.
      Description Memo A description for the expense line item.
      Amount Decimal The source amount for the expense claim (potentially in another currency).
      Currency Code Text The currency code for the expense amount.
      USD Amount Decimal The USD equivalent amount. K2 calculates this value based on the date, amount and currency conversion values.
      Receipt Image An attached receipt for the expense.
      SmartObject Properties
  3. Add associations to the SmartObject to the following SmartObjects.
    Associated SmartObject Association Property Mappings
    Expense Claim Each Expense Claim Line Item has a single Expense Claim and an Expense Claim can have many Expense Claim Line Items. Expense Claim Line Item. Expense Claim Id = Expense Claim.ID
    [Finance].[ExpenseCategory] Each Expense Claim Line Item has a single [Finance].[ExpenseCategory] and a [Finance].[ExpenseCategory] can have many Expense Claim Line Items. Expense Claim Line Item. Category Id= [Finance].[ExpenseCategory].ExpenseCategoryId
    1. Click the ASSOCIATIONS tab in the toolbar. You will associate the Expense Claim Line Item (Smartbox) SmartObject with the Expense Claim SmartObject (generated from the SharePoint Expense Claim list). Click the Add button.
      SmartObject associations create a relationship between two SmartObject data sources. Like a SQL JOIN statement, you associate SmartObjects by mapping common properties. For example, an ID property. Associating SmartObjects creates a parent - child model. In this step, the parent is the Expense Claim SmartObject, generated from the Expense Claim list. The child is the Expense Claim Line Item SmartObject. You will have one parent record and one or more child records associated with the parent.
    2. On the Add Association screen, navigate to the Expense Claim SmartObject. Your screen may be different than the image below, depending on your SharePoint names and subsite structure. Click NEXT.
    3. Configure the association so that each Expense Claim Line Item has a single Expense Claim and an Expense Claim can have many Expense Claim Line Items. Select the Use Existing Property radio button and click NEXT.
    4. Now you need to tell K2 which property it should use to map the child Expense Claim Line Item SmartObject with its parent > Expense Claim SmartObject. Select the Expense Claim ID property, then click Assign. You will map the Expense Claim ID property (from the Expense Claim Line Item SmartObject) to the ID property (from the Expense Claim SmartObject).
    5. In the dialog box, select ID from the drop-down list and click OK.
    6. The Association mappings screen should look like the image below. Click FINISH to complete the association wizard. (Finish is the equivalent of save.)
    7. Next, you will add another association to bind the new SmartObject with the SQL data source that returns expense categories. In a later step, you will use this data source to provide values for the expense claim category drop-down list.

    8. Click the Add button. On the Add Association screen, navigate to the [Finance].[ExpenseCategory] SmartObject, then click NEXT. (Your screen may not match the image below exactly depending on your SharePoint site names.)
    9. Configure the association so that each Expense Claim Line Item has a single [Finance].[ExpenseCategory] and a [Finance].[ExpenseCategory] can have many Expense Claim Line Item. SmartObjects. Select the Use Existing Property radio button, then click NEXT. Once again, each line item record will have a single category, while each category may have many line items.
    10. On the Add Association screen, select the Category ID property and click Assign. You will associate the Category ID property (which will become the category drop-down list control on your form) with the Azure SQL SmartObject. When your form loads, K2 populates the category control with the values it finds from the ExpenseCategory SmartObject.
      In the pop-up dialog box, select the ExpenseCategoryId property, then click OK.
    11. Click FINISH to complete the association wizard.
  4. Finish the SmartObject wizard.
    1. Click FINISH to complete the SmartObject wizard. The finish button is near the upper right corner of your screen. You will return to the K2 Application elements screen.
Review

In this step, you created a new SmartBox SmartObject. SmartBox SmartObjects are K2-provided storage where K2 creates a table on your behalf in the K2 database. This SmartObject stores the line item details. You can use many different types of data sources to store this content, such as SharePoint lists, or other SQL tables. This step demonstrated how to create a SmartBox SmartObject and associate it with other existing data sources. In the next step, you will create the last data source for this application. This data source uses the K2 Tutorial Currency Web Service - service instance created earlier.

Next Step: 6. Create the Expense Claim Currency SmartObject
Expense Claim Application