How To: Configure an editable list view with required fields and rows

You can configure an editable list view to check for a required field, and that a row is not blank. The required field prevents someone from saving an entry to the editable list view and shows a message until they add the required field. The empty row configuration prevents someone from saving or leaving rows blank in the editable list view and shows them a message.

For example, suppose you have an order entry editable list. You want to define data validation so that each row in the order details must contain a value for the Item field. You also want to define validation so that at least one item is added to the editable list view.

Configure an editable list view for required fields and rows

Scenario

In the following scenario, you use rules to configure required field validation for a specific field. You also configure a rule to verify that at least one item is added to the editable list.

In a real world scenario you would probably add other views to the form such as a Customer Details view, to capture the customer information. In this how to, we focus on the validation on the Order Details editable list view.

Steps

In the steps below, you create a SmartObject called Order. You generate an editable list view based on the Order SmartObject and create a form called Purchase Order. You then add the view to the Purchase Order form and configure view and form level rules to check if the required field is empty or a row is blank.

Setup Steps

The following steps set up the scenario from start to finish. If you want to skip the setup steps and view the topic step, go to Configure the View and Form Rules.

  1. Create the SmartObjects
    1. Open K2 Designer and create new category folder called Purchase Order.
    2. From the K2 Designer, create the Order SmartObject as shown below.

      Order


      PropertiesTypeKeyRequiredUnique
      IDAutonumberYesNoYes
      ItemTextNoNoNo
      CodeNumberNoNoNo
      QuantityNumberNoNoNo
      ValueNumberNoNoNo
  2. Generate View
    1. On the Order SmartObject, generate an editable list view.
  3. Configure the Order Editable List View
    1. Open and edit the Order item view.
    2. Select the ID column and remove the column.
    3. Select the Item column and click Count in the Aggregation section. The purpose of the Count is to count how many rows are in the Order view. Later in this how-to, you will use the count option in a rule; if the count is 0, a message will display.
    4. Click Finish and check in the view.
  4. Create the Purchase Order Form
    1. Open K2 Designer and create a new form called Purchase Order.
    2. Add the Order view to the Purchase Order form. Enter Order Details as the view title.
    3. Add a Button control to the Purchase Order form and rename it to Purchase.
      i
    4. Click Finish and check in the form.

Configure the View and Form Rules

In this step you configure the rules for the Order Details view and the Purchase Order form.

  1. Configure the View and Form Rules
    You now configure the When the View executed List item added and When the View executed List item changed rules. These rules determine if the Item field is empty when a row is added or changed on the Order Details view. If the item field is empty, a message displays
    1. Open and edit the Order editable list view.
    2. Select the Rules tab and edit the When the View executed List item added rule.
    3. On the Rule Designer page, select the Conditions tab and add the an advanced condition is true condition. Click an advanced condition to configure it.
    4. On the Rule Designer page, click Add.Add the Item Text box from the Controls > Add/Edit Row in the Context Browser. In the Operator section select _" Is Empty. Click OK.
    5. Select the Actions tab and add the Show a message action and click configure.
    6. On the Show a Message to the User page configure the Title, Heading and Body as shown below. Click OK.
    7. Select the Conditions tab and add an Else condition to the rule as shown below. Click OK.
    8. Repeat the above steps on the When the View executed List item changed rule.
    9. Click Finish and check in the views.
    10. You now configure the form rule for the Purchase button. The form rule uses the count option you added to the Item column of the Order Details view. If the count is greater than 0, then row is saved, if the count is less than 0, a message is shown, stating that the rows are blank.

    11. Open and edit the Purchase Order form.
    12. Select the Rules tab and click Add Rule.
    13. On the Rule Designer page select the Events tab and add the When a control on the Form raises an event event.
    14. Select the Conditions tab, add the an advanced condition is true condition and click an advanced condition to configure it.
    15. On the Rule Designer page click Add. Add the Count Data Label from the Order Editable List > Controls > Footer Rows in the Context Browser. In the Operator section select > Greater Than and add 0 in the Right section. Click OK.
    16. On the Rule Designer page select the Actions tab, add another Execute a View method rule and click select View. Select the Order Editable List view and click select Method. Select the Save method and click configure.
    17. On the On Order Editable List View, Execute the Save Method page, click Auto Map in the Input Mappings section and click Next. There are no Output Mappings, click Finish.
    18. On the Rule Designer page select the Conditions and add the Else condition. Select the Actions tab and add a Show a message action and click configure.
    19. On the Show a Message to the User page, add Row is Blank to the Title and Heading fields and add The row is blank. Please complete the row before submitting your purchase order. in the Body field. Click OK.
    20. Click OK again, click Finish and check in the form.
  2. Test the Solution
    In this step you create a new Purchase Order and add items to your order.
    1. From the K2 Designer, locate the Purchase Order form and click Run.
    2. On the Order Details view, click Add or (Add new row) and do not add any information in the new row. Click the Purchase button.
    3. Notice the Row is Blank message displays, because the Count aggregate is 0 on the Order Details view.
    4. Complete the newly added row and click Save then Purchase. Notice the row is saved because the Count aggregate is greater than 0.
    5. On the Order Details view, add a new row and only enter information on the Code, Quantity and Value fields and click Save or click out of the newly added row.
    6. Notice the Item Description Required message displays because the Item field on the Order Details view is empty. Click OK.
    7. Provide an item description in the Item field and click Save again. Notice the row is saved successfully because you completed the required Item field.
Review

You created a SmartObject called Order Details. You then generated a editable list view, created a form and added the view to the form. You configured rules on the view level which determined if the Item field was empty, then a message showed stating the Item field is required. You then configured a form rule on the Purchase button that if the count is less than 0 on the Order Details view, then show a message stating the row is blank.