Share via


Add data from the user in Project Siena

 

Add data from the user to a collection if you want to keep the information after the Project Siena app is closed and reopened. Track temporary data from the user (for example, a running total of costs that automatically updates as the user adds items) in a context variable.

Get a general overview of Project Siena with links to resources such as sample apps, video tutorials, and forums.

Prerequisites

Add data from the user to a collection

Create a collection that has one column

  1. Add an input-text box, and name it Destination.

  2. Add a button, and set its OnSelect property to this function:

    Collect(Destinations, Destination!Text)

  3. (optional) Name the button AddButton, and set its Text property to Add.

    An input-text box, named Destination, and a button, named AddButton.

  4. Press F5, type some text into the box, and then click the button.

  5. Alternate typing text into the box and clicking the button a few times.

  6. Press Esc, press Alt-D, and then click Collections to display the collection you created.

    Preview of a one-column collection, named Destinations

Create a collection that has more than one column

  1. Add two input-text boxes, and name them City and State.

  2. Add a button, and set its OnSelect property to this function:

    Collect(Destinations, {Cities:City!Text, States:State!Text})

  3. (optional) Name the button AddButton, and set its Text property to Add.

    Two input-text boxes, named City and State, and an Add button

  4. Press F5 to open Preview.

  5. Type some text into each box, click the button, and then repeat a few times.

  6. Press Esc, press Alt-D, and then click Collections to display the collection you created.

    Preview of a two-column collection named Destinations

    Note

    Use the same function to add rows to an existing collection that contains multiple columns.

Add one or more columns to an existing collection

  1. Create the custom gallery that this procedure describes.

  2. (optional) Indicate which gallery item is selected.

  3. Add a slider, name it OrderQty, and move it under the gallery.

  4. Add a button, set its Text property to Add, and move it under the OrderQty slider.

    A gallery (with two columns), a slider, and an Add button

  5. Set the OnSelect property of the Add button to this expression:

    Collect(OrderList, {Name:PriceGallery!Selected!Name, Qty:OrderQty!Value, Cost:OrderQty!Value*LookUp(PriceList, PriceGallery!Selected!Name in Name, Price)});SaveData(OrderList, "orderfile")

    When you click this button later in this procedure, you'll create and save a collection named OrderList. The collection will contain the name of a product that you specify in the gallery, a quantity that you specify with the slider, and the total cost calculated by multiplying the quantity by the price of the product.

  6. Set the OnVisible property of the screen to this expression:

    If(IsEmpty(PriceList), LoadData(PriceList, "pricefile"));If(IsEmpty(OrderList), LoadData(OrderList, "orderfile"))

  7. Press F5 to open Preview.

  8. Click a product in the gallery, specify a value with the slider, and then click Add.

  9. Repeat the previous step, and then press Esc to return to the design workspace.

  10. Press Alt-D, and then click Collections to display a preview of the OrderList collection.

    A preview of the OrderList collection, which has three columns

  11. Press Esc to return to the design workspace.

    Note

    To remove all items from the order list, add a button, set its Text property to Clear, and set its OnSelect property to this expression:

    Clear(OrderList);SaveData(OrderList, "orderfile")

    To remove one item at a time, show the OrderList collection in a gallery, and then set the OnSelect property of a label in that gallery to this function:

    Remove(OrderList, ThisItem);SaveData(OrderList, "orderfile")

Track dynamic data from the user

  1. Name the default screen FilterScreen, add another screen, and name it GalleryScreen.

  2. On the GalleryScreen screen, create the custom gallery that the first procedure in Show, sort, and filter a data set describes.

    A gallery with three columns and five rows

  3. On the Filter screen, add a drop-down list, name it FilterList, and set its Items property to this function:

    PriceList!Name

    A dropdown list, named FilterList, set to show names in a price list

  4. On the Filter screen, add a Next arrow (under Shapes), and set its OnSelect property to this expression:

    Navigate(GalleryScreen, ScreenTransition!Fade, {FilterName:FilterList!Selected!Value})

    A Next arrow with the OnSelect property showing

  5. On the Gallery screen, set the Items property of the gallery to this function:

    Filter(PriceList, FilterName in Name)

  6. On the Filter screen, press F5, choose a product in the drop-down list, and then click the Next arrow.

    Only the product you specified appears in the gallery.

Create a running total

  1. Create the custom gallery that the first procedure in Show, sort, and filter a data set describes, name it PriceGallery.

  2. (optional) Delete the label that shows the maker of each product, and resize the rectangle and the gallery to better fit the remaining data.

  3. In the first item of the gallery (the template), select the label that shows the name of each product, and set its OnSelect property to this function:

    Collect(OrderList, {Name:ThisItem!Name, Price:ThisItem!Price});UpdateContext({RunningTotal:RunningTotal+ThisItem!Price})

    The OnSelect property of a label in gallery

  4. Add a label, and set its Text property to Text(RunningTotal, "$##,###").

  5. Press F5, and then click one or more products in the gallery one or more times.

    The label shows the cumulative price of the products that you specify.

    A gallery with a label under it, showing a dollar amount

  6. (optional) Add a button that removes all items from the OrderList collection and sets the running total to 0:

    1. Add a button, set its Text property to Clear, and set its OnSelect property to this expression:

      Clear(OrderList); UpdateContext({RunningTotal:0})

      Clear button with its OnSelect property

    2. Press F5, click the Clear button, and then press Esc.

  7. (optional) Remove items from the OrderList collection one at a time, and update the running total each time:

    1. If you just cleared the OrderList collection, click F5, click some items in the PriceGallery, and then press Esc.

    2. Copy the PriceGallery, paste it, and then name the copy OrderGallery.

    3. Set the Items property of the OrderGallery to OrderList.

    4. In the first item of the OrderGallery (the template), select the label that shows the name of the product, and set its OnSelect property to this expression:

      UpdateContext({RunningTotal:RunningTotal-OrderGallery!Selected!Price});Remove(OrderList, ThisItem)

    5. Press F5, and then click one or more products in the PriceGallery one or more times.

      The items that you click appear in the OrderGallery, and the running total shows the total cost.

    6. Click an item in the OrderGallery.

      The item that you specified is removed from the OrderGallery, and the running total decreases by the appropriate amount.