Create and manage a collection in Project Siena

 

If you create a collection in Project Siena, you can gather data from a user and then save that information, or you can modify data from another source and then save your changes. For an overview of Project Siena and links to resources such as sample apps, video tutorials, and forums, see Project Siena.

Prerequisites

Create (or add rows to) a collection from data that a user provides

  1. Add an input-text control for each column in the collection you want to create or update.

    For information about how to add and name controls, see Create your first app with Project Siena.

    For example, you could add two input-text controls, named Year and ViolinRevenue, to create or update a collection that contains two columns.

  2. (optional) Add labels that identify the purpose of each control.

  3. Add a button, and set its OnSelect property to a function that follows this syntax:

    Collect(CollectionName, {ColumnName1:NameOfInputControl1!Text, ColumnName2:NameOfInputControl2!Text, ...})

    For example, you could use this function to create or update a collection named ViolinRev that contains two columns. A column named Years will contain data from an input-text control named Year, and a column named Violins will contain the numeric value of data from an input-text control named ViolinRevenue:

    Collect(ViolinRev, {Years:Year!Text, Violins:Value(ViolinRevenue!Text)})

  4. (optional) With the button selected, click Data if it appears in the lower-left corner, and then set the Text property of the button to Collect.

  5. Press F5, add data to each of your input-text controls, and then click the button.

  6. Repeat the previous step for each row that you want to add, and then press Esc to return to the design workspace.

    Note

    You'll create duplicate items, intentionally or not, if you click the button more than once without changing the data in any input-text control. For information about how to remove items you don't want, see Remove one or more rows of data.

  7. (optional) Preview your collection by pressing Alt-F, clicking App Data, and then clicking Collections.

    Viewing a collection with one series of data

  8. (optional) Create a custom gallery to show your collection in your app.

    Two labels, two input boxes, a button, a gallery

    For information about how to format text as currency, see Text. For information about how to save data in a collection before you close your app and automatically load that data into a collection when you reopen the app, see Save data.

Create a collection by adding data from another source

  1. Add data from another source, add a Button control, and set the OnSelect property for the button to a function that follows this syntax:

    Collect(CollectionName, DataSourceName)

    For example, you could use this function to create a collection named Products from a table named Contoso that you imported from Excel:

    Collect(Products, Contoso)

    You can create a collection from only one column in a data source by using this syntax:

    Collect(CollectionName, DataSourceName!ColumnName)

  2. Press F5, click the button, and then press Esc to return to the design workspace.

Create a collection by adding a column to an existing collection

  1. Add a gallery, and set its Items property to a function that follows this syntax:

    AddColumn(NameOfCollectionToUpdate, "NameOfColumnToAdd", Expression)

    For example, you could add a column to a collection named RevenueByProduct that follows this structure:

    Years

    Violins

    Trombones

    Bongos

    2012

    $21,000

    $15,000

    $14,000

    2013

    $26,000

    $17,000

    $19,000

    2014

    $28,000

    $21,000

    $23,000

    You could then use this function to add a column, named AnnualRevenue, that showed the total revenue for each year:

    AddColumn(RevenueByProduct, "AnnualRevenue", Violins + Trombones + Bongos)

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

    Collect(NameOfNewCollection, NameOfGallery!AllItems)

    For example, you could use this function to create a collection named RevenueByYear that contains all the data in a gallery named FullTable:

    Collect(RevenueByYear, FullTable!AllItems)

  3. Press F5, click the button, and then press Esc to return to the design workspace.

    The collection named RevenueByYear contains the new column along with the four other columns, and you can use that data to create a chart, for example.

  1.  Create a gallery that shows data in a collection.

  2. Click the label in the left-hand column of the first item in the gallery, and then set its OnSelect property (in the Behavior category) to a function that follows this syntax:

    Collect(CollectionName, ThisItem)

    For example, you could use this function create a collection named WishList that contained only those items that you click in the gallery:

    Collect(WishList, ThisItem)

  3. Press F5, click a few items in the gallery, and then press Esc to return to the design workspace.

  4. Press Alt-F, click App Data, and then click Collections to display a preview of your collection.

    Preview of a collection with two items in it

Remove one or more rows of data from a collection

  1. Create a collection, and then create a custom gallery to show your data.

  2. In that gallery, click the label in the left-hand column of the first item, and set the OnSelect property for that label to a function that follows this syntax:

    Remove(CollectionName, ThisItem)

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

    Clear(CollectionName)

  4. Press F5, and then click an item in the gallery to remove that item from the collection.

  5. Click the button to remove all items from the collection, and then press Esc to return to the design workspace.

Save data in a collection

  1. Create a collection, and then create a custom gallery to show your data.

  2. Add the SaveData function after the Collect function:

    Collect(CollectionName, Expression);SaveData(CollectionName, "LocationName")

    For example, if you followed the steps in the first procedure in this topic, change the OnSelect property of the button to this function:

    Collect(ViolinRev, {Years:Year!Text, Violins:Value(ViolinRevenue!Text)});SaveData(ViolinRev, "RevenueFile")

  3. In the gallery, click the control that you used to remove an item, and set the OnSelect property for that control to a function that follows this syntax:

    Remove(CollectionName, ThisItem);SaveData(CollectionName, "LocationName")

  4. Set the OnVisible property for the screen to a function that follows this syntax:

    If(IsEmpty(CollectionName), LoadData(CollectionName, "LocationName")

  5. Add or remove one or more items in your collection, close Project Siena, and then reopen it..

  6. Press Alt-F, click App Data, and then click Collections to confirm that your data was retained.

See Also

Build a function in Project Siena