Data
This data tutorial will be going over Datamodels, DataObjects, and Enums.
Datamodels
Datamodels are the container that contains all your data, useful for containing data for different separate functions (User interaction, Database, Reporting).
Creating Datamodel
The following are the steps needed to create a datamodel:
- Navigate to the settings
- Navigate to the Data tab, and then select the datamodel tab
- Open the overview and create your data model by clicking on the + Create New button
Note: For this example we assume that you have already created a datasource and configured it. If not, please refer to the documentation on how to create a datasource
Creating a DataObject
- Open the newly created Datamodel and choose the DataObjects tab
- Create a new DataObject by clicking on the + Create New button
- Add fields and types
- Name the table
- Save
Enums
One other important data type is the Enum or the Enumeration. They are essentially a group of certain values/constants that doesn’t get appended to or removed during the app execution.
Creating Enums
- Navigate to the settings page
- Open the data tab then the data model tab
- Open the data model we created in the last example, now click on Data Structures and then Enums
- Create your Enum from the + Create New button
- By clicking the + button in the middle you can add a new Enum value. And these values are unchanged and constant. You can reference these values by an Id that you can get by clicking to the left of the Enum name
- Name the Enum and save it
Operations on Datamodels
Now you have an Enum, and a data table and you are probably wondering how can I add data to the data model? There are many ways to add the data and you can find it in the documentation but for now we will go about how we add the data from a page.
For this example, we assume that you have already made a data object that has 3 data fields, two for string and for an integer value. We also assume that the page is empty and has nothing except the base grid.
Navigate to the page where you want your data table
Open the AppBuilder by clicking F2
Note: When you open the AppBuilder, please select edit mode and not view mode. When you select the edit mode the page becomes locked and you are the only one allowed to change it until the changes are accepted in the ChangeLog.
Divide the base grid into 2 different rows
In the first row, add a flex add 3 TextBoxes and Buttons inside that flex
Customize the elements as wanted
Add a DataTable element in the second row
- Now go to the base grid properties and add a data source. And also go to the textboxes and the checkbox and bind the data relevant to the control item
Note: The Datasource type is dynamic
- After adding the data source, go to the datatable properties and choose the data table columns and select all the data you want to show
Note: you must select the _Id as must be used when fetching data and filtering and so on
Now you have to create the workflows to add, save, and delete the data.
Add workflow
- Drop a "Add Item" WFB which uses the flex element
- Drop a "Refresh" WFB to be used on the DataTable
- Save as add
Save workflow
- Drop a "Save Item" WFB which uses the flex element.
Note: Link the successfully recreated and saved successfully to the next step
- Drop a "Refresh" WFB to be used on the DataTable
- Save as save
Delete workflow
This requires 2 different workflows
- One for selecting the item to delete
- One for the actual deletion
Selection
- Drop a "Get List Item" WFB and set it to get the first entry.
Note: this is done because when we later select any item from the datatable the selection is always an array of objects and what we are doing here is just casting it into one object
- Drop a "Read Properties" WFB and set it to read the property name "_Id" and assign it a status key (Ex. idToDelete)
- Drop a "Read Data" WFB and select your datasource and filter it by comparing "_Id" with "idToDelete"
- Drop a "Get List Item" WFB once again
- Drop a "Set Values" WFB and select the flex element
- Save as onSelect
Deletion
- Drop a "Delete Item" WFB which uses the flex element
- Drop a "Refresh" WFB to be used on the DataTable
- Save as delete
After making the workflows, we have to link them with events.
- Add the workflows on their respective buttons by toggling the "MouseClick" event and assign respective workflow. (Add, Delete, and Save)
- On the Datatable, bind the "OnSelect" event to the onSelect workflow
That should be it! Try it out by adding, saving and deleting.
Datatable Changes
Lets assume you were instructed to change the table schema to add 2 elements, an isActive flag and the employee's department
- Navigate to DataObjects page in the settings
- Add the isActive field and set default as true
- Add the department and pick the Enum you created before
These changes should be reflected on the page as well
- Add a combobox inside the flex and data bind it to the department field
- Add a checkbox inside the flex and data bind it to the isActive field
- Modify their properties to make them editable
- Add the 2 columns to the datatable and set them to visible to be able to show them in the datatable
That's it! The page now functions as intended.
Note: if there were any previous data points the new values will be null so it should be changed when the new columns are added. This can be done using a service side workflow or done manually.
Images
To store an image in your datatable:
Make sure you have a media source.
- In the settings go to the data tab
- Inside the data tab, go to the media sources
- Add your preferred media source and its credentials
- Make sure you have a data source
Create a DataObject for an image class
- Create a new dataobject named “Images”
- Create 2 text data fields
- Name the first “url”
- Name the second “name”
If you want to include the image in your DataObject:
- Create a new class data field
- Select the "Images" DataObject you created for the data model without reference
For page changes:
- Drop a layout inside the flex (Grid, Repeat, etc). For multiple images, use a Repeat layout
- Bind it to the image field
- Add an upload button, and set it's type as image
- Drop image element in the layout
- Bind the image element to the URL
- Select Media Source
- Optionally, drop a text box for the title
You now need a workflow to display the image, create a workflow that is triggered on the event on Upload Complete
Inside the workflow drop the following:
- For Loop
- Set Status as image
- Define object. Select the data source for the image. The default value: name => GetProperty(image; "OriginalFilename") and the url=> GetProperty(image; "ResultingFilename")
- Add item to list (If multiple images)
- Set values onto the image layout
Note: All changes made are saved locally on your account, and are not visible to the all other users. To make them visible to all users please accept the changes in the ChangeLog Overview in the settings.