Show TOC

Procedure documentationStore Data in a Data Store for Later Use Locate this document in the navigation structure

 

A data store is a central data container in which you temporarily store data for later use. You create one data store per iView. To do so, you can place a single data store instance in the model, or, for convenience purposes, you can place multiple data store elements, all pointing to the same data store. The connecting lines to the input port of the data store are of data mapping type. The values in the data store are accessed using expressions.

You create one data store per iView. To do so, you can place a single data store instance in the model, or, for convenience purposes, you can place multiple data store elements, all pointing to the same data store.

The connecting lines to the input port of the data store are of data mapping type. The values in the data store are accessed using expressions.

Procedure

  1. In your model, drag out from the out port of the UI component whose data is to be stored, and choose Data Store from the context menu.

  2. Double-click the data store to open the Configure Element task panel.

  3. At the bottom of the task panel, click the Add (Add) button to display the Field Properties dialog box.

  4. In the Field name field, define a virtual field for the data store and click OK.

  5. Click the connecting line to the data store, and name the event according to the action that should be performed for adding items to the data store, for example: Add_Item.

  6. In order to map values from the table to the data store, create a dynamic expression by clicking fx in the first row of the Assigned Value column and choosing Enter formula. In the Assign Value dialog box, enter the required expression. An example of such an expression is given in step 5 of the following example.

  7. To create a complementary data store that clears the store, for example, repeat steps 1 - 6.

  8. On the Layout board, create buttons for transferring items (and removing, if needed) to the data store:

    1. Right-click the UI component from which values are to be sent to the data store and choose Create Toolbar from the context menu. The Create Toolbar Buttons dialog box is displayed.

    2. Create buttons named logically, and assign a Custom action named according to the event defined for them (step 5).

    3. Click OK.

  9. On the Design board, drag a Form View icon from the Compose Model task panel to create a free-standing form that represents the data store in the iView.

  10. Define a virtual field to display the data store values:

    1. At the bottom of the Configure Element task panel, click the Add (Add) button to display the New UI Control dialog box.

    2. Choose Expression Box, name it appropriately, and click OK.

    3. Double-click the row of the new field to display the Control Properties dialog box.

    4. In the General tab, click Formula to the right of the Expression field. The Computed Value dialog box is displayed.

    5. In the list of functions in the right pane, expand the Data Store group, and double-click the name of the field in the data store. This is the field whose values will be transferred to the form.

    6. Click OK to close the dialog box.

  11. Click OK in the Control Properties dialog box.

Example

In this example we will use the Salesorders A model and add to it a data store. We will then create a form called “Cart” into which users can transfer materials from the Salesorders table. Materials transferred to the cart will be concatenated into one string divided by semicolons.

  1. Import the Salesorders A model or create it from scratch.

  2. On the Design board, drag out from the out port of Sales Orders Grid and choose Data Store from the context menu.

  3. In the Configure Element task panel, create a virtual field for the data store, named Items.

  4. Click the connecting line to the data store, and name the event Add_to_Cart.

  5. In the first row of the Assigned Value column of the table, create an expression that maps values from the table to the data store. Leave the Default value field blank, and click OK.

    1. Double-click in the Assigned Value column to display the Assign Value dialog box (Expression Editor).

    2. Enter the following expression:

      LISTCONT2IF(CONTAINS(STORE@Items,@MATERIAL),STORE@Items,STORE@Items &(IF(LEN(STORE@Items)>0,'; ',''))&@MATERIAL) LISTCONT

      This expression checks whether the MATERIAL value transferred to the Items field is already contained in it. If it is not, the value is concatenated with the existing values.

    3. Click Check to validate the expression, and then click OK.

  6. Create another data store as described in steps 2-5. However, name the event Clear_Cart and map the value “ as the Assigned Value of the input field (this will assign an empty value to the Items field).

  7. On the Layout board, create buttons for activating and clearing the data store items (step 8 in the previous Procedure). On the Layout board, right-click the Sales Orders Grid and choose Create Toolbar from the context menu. The Create Toolbar Buttons dialog box is displayed. Add a second button named Clear Cart, with Clear_Cart as the action name.

    1. Add a button named Add to Cart, with a Custom action called Add_to_Cart.

    2. Add a second button named Clear Cart, with Clear_Cart as the action name.

  8. On the Design board, create a free-standing form called Cart. Place it above the Sales Orders Grid.

  9. Define a virtual field to display the data store (cart) values and name the field Items (following step 10 in the previous Procedure).

  10. Close the dialog boxes.

    Your model should look similar to the following:

    Design Board (Design Board)

  11. Rearrange the layout, placing the cart along the top of the iView (you can use the Resize to Fit Window option in the context menu to stretch it along the width of the iView). Place the Sales Orders Grid to the right of the Input Form.

  12. Deploy. The runtime results should be similar to the following:

    Runtime (Runtime)

Result

When the user selects an item and clicks Add to Cart, the Material name is displayed in the Items list of the cart. When additional items are selected, they are concatenated in the Items field.