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
- Create your first app to understand how to perform basic tasks, such as adding a control.
Add data from the user to a collection
Create a collection that has one column
Add an input-text box, and name it Destination.
Add a button, and set its OnSelect property to this function:
Collect(Destinations, Destination!Text)
(optional) Name the button AddButton, and set its Text property to Add.
Press F5, type some text into the box, and then click the button.
Alternate typing text into the box and clicking the button a few times.
Press Esc, press Alt-D, and then click Collections to display the collection you created.
Create a collection that has more than one column
Add two input-text boxes, and name them City and State.
Add a button, and set its OnSelect property to this function:
Collect(Destinations, {Cities:City!Text, States:State!Text})
(optional) Name the button AddButton, and set its Text property to Add.
Press F5 to open Preview.
Type some text into each box, click the button, and then repeat a few times.
Press Esc, press Alt-D, and then click Collections to display the collection you created.
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
Create the custom gallery that this procedure describes.
(optional) Indicate which gallery item is selected.
Add a slider, name it OrderQty, and move it under the gallery.
Add a button, set its Text property to Add, and move it under the OrderQty slider.
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.
Set the OnVisible property of the screen to this expression:
If(IsEmpty(PriceList), LoadData(PriceList, "pricefile"));If(IsEmpty(OrderList), LoadData(OrderList, "orderfile"))
Press F5 to open Preview.
Click a product in the gallery, specify a value with the slider, and then click Add.
Repeat the previous step, and then press Esc to return to the design workspace.
Press Alt-D, and then click Collections to display a preview of the OrderList collection.
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
Filter a gallery on another page
Name the default screen FilterScreen, add another screen, and name it GalleryScreen.
On the GalleryScreen screen, create the custom gallery that the first procedure in Show, sort, and filter a data set describes.
On the Filter screen, add a drop-down list, name it FilterList, and set its Items property to this function:
PriceList!Name
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})
On the Gallery screen, set the Items property of the gallery to this function:
Filter(PriceList, FilterName in Name)
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
Create the custom gallery that the first procedure in Show, sort, and filter a data set describes, name it PriceGallery.
(optional) Delete the label that shows the maker of each product, and resize the rectangle and the gallery to better fit the remaining data.
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})
Add a label, and set its Text property to Text(RunningTotal, "$##,###").
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.
(optional) Add a button that removes all items from the OrderList collection and sets the running total to 0:
Add a button, set its Text property to Clear, and set its OnSelect property to this expression:
Clear(OrderList); UpdateContext({RunningTotal:0})
Press F5, click the Clear button, and then press Esc.
(optional) Remove items from the OrderList collection one at a time, and update the running total each time:
If you just cleared the OrderList collection, click F5, click some items in the PriceGallery, and then press Esc.
Copy the PriceGallery, paste it, and then name the copy OrderGallery.
Set the Items property of the OrderGallery to OrderList.
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)
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.
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.