Datasets as input types
We highly recommend doing the guided tour before you read this section. Furthermore, knowledge on custom input types and datasets is highly recommended, just as some basic understanding of repeats and model structure.
Sometimes, you will need something more than your own custom input types. More specifically, you might need an input type that depends on a dataset. This dataset can be made in the model itself or could be imported from a database.
To do so you will need an input type based on a dataset. For example, the user might enter personal details for several people. You can then ask the user to select the people whose details should end up in the report. Since you do not know the people the user will enter, you’ll need to store them in a dataset.
Setting up the model
To demonstrate how this works, we’ll first need a model. We’re going to make a very simple model that repeats a question a couple of times. The model will then put the answers into a dataset and use that to ask the user something.
To do so, please create a new model. Add a graph
g_input to your starting node. Create a repeat to repeat the graph three times. You should add a question in the graph
g_input for someone’s name. Last but not least, in the node
main.start, convert the graph into a dataset with the
graphtodataset('g_input') function. The result is shown below in the image.
Note that the formula
getvaluefromcallingnode('counter') is optional: it will only provide the user with some information.
The model right now gathers some names from the user and puts them in a dataset. You can check this by running the model, putting in some names and then use the data inspector to check if everything is alright. When you double-click the dataset, it should look similar to the picture below:
Adding the question
Now, let’s get started with the real work. We want to user to make a selection from the names he or she just entered. We first need to import the dataset to this node. Therefor, create a new formula (
ACTIONS > Formula) with
start.ds as value. Next, we’re going to add a question to the node question through
ACTIONS > Question. In the question screen, check the ‘Use dataset’ box at the bottom of the screen and enter
ds as the name (that is the name of our dataset).
You can select several input types here. For the example we will use the checklist. The checklist allows to user to select zero or more options. We will discuss the other options later on.
After selecting the checklist, ensure that the dataset is correctly set to
g_input and proceed to enter
start.name for the field and
start.selected the checkfield. Your screen should now look like this:
Running and checking the model
If you’ve done everything correctly, running the model should yield the following screen. Note that the names are entered in the previous nodes, and will probably differ from your model.
Differences between input types
As you might have seen by now, you can select other input types. It is, however, important to know the difference between them. Some, as with the checklist, require only one dataset. Others, such as the drop-down list, need two datasets. In such a case, you’ll need to create your own dataset as we did before (in
main.start). The difference is the way you ask the question.
The drop-down list has a field called ‘Variable to use’. In this field, you enter the dataset that acts as a template for your question. In our case, that is
main.start.ds. The question itself is, however, a dataset with a different name. In this example, we use
ds2 as name.
Note that this way uses two datasets! One as a template (
main.start.ds) and one as a result of the question (
main.question.ds2). So if you want to see the results, you’ll need to use the latter! The template dataset remains unchanged.
If you use a dataset, it happens that you create one based on earlier answers (e.g. with the function graphtodataset) and then show it to the end user. If the user then jumps back, changes things and the dataset is changed (new or deleted rows), the values given by the user are lost. Use ‘remember dataset’ to get the server to try to hold on to the original values. This checkbox is only available with the ‘grid’ and the ‘checklist’.
For the grid to handle such a potentially complex structure it needs to know how to recognize the different rows. This is done by a key. This key must be unique for the different rows, just like in a database. The server will use the key to determine if there are new, changed or deleted rows.
A special type of question in the Berkeley Studio is the grid. A grid presents information in a table, and if needed, allows users to edit this information. Furthermore, you can present the user with an empty grid (table) and ask them to fill in the required data.
As grids are completely based on data sets, we incorporated grids into the tutorial on data sets. If you are familiar with data sets and you want to jump straight into the action, please see Using the dataset II under ‘Presenting the selection’. Dynamic columns, dynamically hiding colums of the grid, is explained here.