Creating Defined Data Structures (Advanced)Last Updated: 08/18/2016 Introduced in Verision: 2.0
Custom data structures represent real or abstract objects by their use of data members – basic units of information which can be thought of as variables belonging to the object you wish to represent. Custom data structures can be created in the folder System > Designers > Data Structures.
In the example, we will:
- Create a defined data structure.
- Add data members to the data structure with data types of string, Boolean, integer, and Date Time.
- Set how the data structure can be saved.
Our example data structure will be called UserInfo and contain variables of demographic information not already represented by User Accounts, including: first and last name, address, sex, age and date of birth.
Data structures are contained in the folder System > Designers > Data Structures.
Some structures are the most basic variables available to a programmer: integers, bytes, booleans, strings and others. These structures appear throughout much of the platform and have no members. In fact, they are the data structures we’ll typically use as members for more complex structures.
At least two of these complex structures are already defined: Decisions and DecisionFramework. These data structures are like our custom structures in that they rely upon data members to define their properties. The key insight here is that data structures can be nested inside each other. This allows us to create data structures of nearly unlimited complexity, up to and including the platform itself.
To begin building our example data structure, we will click the button Add > Defined Data Structure.
A custom data structure has only a few components: a name, a namespace and super class (both of which are described in other examples), data members and an option for storage. We’ll begin by naming our custom data structure “UserInfo” and assigning it members.
We enter a name in the Type Name field, then click the Add button next to the Data Members box.
Our first data member will be called FirstName, and will contain our user’s first name. In computer programs, words and sentences are represented as strings of characters, which is why we call them Strings. Once we’ve declared a name and type for FirstName we’ll click Save.
We’ll repeat the process to add two more data members, LastName and Address.
We click the Add button next to the Data Members box, enter their names, retain the Data Type of String and click Save.
Our next data member, Sex, is a little different. For our example, we would like to represent Sex as either “Male” or “Female.” When we want to restrict a variable to only two possible values, our best option is to make its type Boolean. A boolean variable can only be true or false. Later, we can programmatically associate “Male” or “Female” with “True” or “False”, but for our present needs, this will suffice.
To change the data type to Boolean, we click the Data Member Type selector, select the data type from the list, then click OK.
For Age, we want to restrict our variable’s value to whole numbers only. The platform offers multiple numeric types, but the most appropriate for our purposes is the 32-bit encoded integer, or Int32.
Our final data member, DateOfBirth, must be a valid calendar date. We could represent a date as a string, but the DateTime type comes with special validation and encoding rules that prevent invalid dates, such as February 30th, from being saved.
Now that all of our data members are added, we need to define whether and how our data structure can be saved in the Storage Options drop-down list. We want to be able to save this structure, so we’ll change the value to DatabaseStored and click Save to save our custom data structure.
This completes the creation of our custom data structure. It now appears in our list of available data structures, and can be used anywhere in the platform.
If we examine the details of our data structure, we can see that it contains the data members which we added.
Should we decide later on that we would like to modify or even delete our custom data structure, menu options are available to do just that.