Work with Variables and Types

An application artifact describes the variables, types and action chains that can be used in any page in your application, as well as other configuration settings and properties of the application. When you open an application artifact, various editors are available for examining and modifying the artifact.

About Variables and Types

Variables can be used in any page, and custom types can be used to define the data of any variable. Variables and types can be created in application, flow and page artifacts. Variables created in an application are application-scoped and can be used to store data that can be used anywhere within the application, both within and across flows and pages, for example, for a login name. Variables created in a flow are flow-scoped and can be used in any of the pages within that flow. Variables created in a page can only be used within that page.

You use variables to store data that can be used by actions and page components in your application. Application variables are application-scoped, so their use is not limited to a specific page and they are accessible from any of the pages of an application. Application variables are useful for storing states, input parameters, login details and other data that you want to be accessible both within and across flows and pages. For each variable you must specify a Type property to define the type of data that is stored in the variable. See Understand Variables.

You use types to define the data type and structure of a variable, and every variable must be assigned a type. Types can be application-scoped, flow-scoped or page-scoped, and can be assigned to application, flow and page variables. There are two kinds of types that can be assigned to variables: built-in types and custom types. Standard built-in types are used to specify data that are a primitive type, a structure or a simple array or collection, for which each field can either be a primitive or a structure. There are also two special built-in types that are typically used for storing data retrieved from an endpoint and are used when some operations need to be performed on the data: Array Data Provider and Service Data Provider. For details about how to use types in the page model, see Types.

You can define custom types from an endpoint or your can define a custom object or array.

Create Variables in Artifacts

You can create variables in application, flow and page artifacts. Variables are assigned a scope that is based on where they are created, and the scope determines where they can be used. When you are deciding where to create a variable, you should consider where it might be used.

Each variable is required to have a unique name (Id) and a type. When you create a variable you must specify one of the built-in types or a custom type. After you create the variable, you can edit its properties and attributes in the Variables tab for example, to identify it as an input, or to add attributes if its type is array or object. You can also use a variable to trigger an action chain when its value changes. You can use the Events tab in the Variable Information pane to add onValueChanged event actions and specify the action chain the change will initiate.

To create a variable in an artifact:

  1. Open the Variables tab in the Variables editor of the artifact.

    The Variables editor contains a Variables tab and a Types tab. The Variables tab displays a list of the variables that are already defined for the artifact. You can enter a string in the filter field to limit the list to variables containing the string. The Variable Information pane is used for editing the details and event actions for the selected variable.


    Description of webapp-variables-editor.png follows
    Description of the illustration webapp-variables-editor.png

    You will see a message if no variables are defined.

  2. Click + Variable to open the New Variable dialog box.
  3. Type a name for the variable in the Id field and select a type in the Type dropdown list.

    The dropdown list displays the built-in types as well as any custom types that can be applied to the variable.


    Description of page-designer-variables-create.png follows
    Description of the illustration page-designer-variables-create.png
  4. Click Create.

    You can select the Create Another checkbox to immediately create another variable.

After you create a variable you can select the variable in the list and edit its properties and add event actions in the Variable Information pane.

Create a Custom Type

You create a custom type when you want a type that defines an array or an object, and you want to individually add each of the attributes that define the type’s data structure.

To create a custom type:
  1. Select your application, flow or page artifact in the Navigator.
  2. Open the Types tab in the artifact’s Variables editor.

    The Types tab displays all the types defined for the artifact.


    Description of var-type-responsetype.png follows
    Description of the illustration var-type-responsetype.png
  3. Click + Type and select Custom in the menu.

    The New Type dialog box appears when you select Custom in the menu.


    Description of var-type-custom-new.png follows
    Description of the illustration var-type-custom-new.png
  4. Type a name for the new type and choose either Object or Array as the type. Click Create.
    When you click Create, the new type is added to the list in the Types tab. You now define the structure by adding attributes.
  5. In the Types tab, click Add ( Add icon ) next to the new type to add an attribute.
  6. Enter the name and select a type for the new attribute. Click Create.
    You can select the Create Another checkbox if you want to immediately add another attribute to the type.
You can continue to refine the data structure of the type by adding attributes.

Create a Custom Type From an Endpoint

When you create a custom type from an endpoint, you define a data structure by selecting an endpoint and then choosing from the fields available at the endpoint. Custom types can be used to define the structure of any variable in your application.

For example, when sending a request to an endpoint getall_Contact you might want the structure of the response to be an array with the id and a few specific fields (a string name and a string email). You can create a custom type from the endpoint and select the fields that you want in the response. All variables that are assigned this custom type will have the same data structure.

To create a custom type from an endpoint:

  1. Select your application, flow or page artifact in the Navigator.
  2. Open the Types tab in the artifact’s Variables editor.
  3. Click + Type and select From Endpoint in the menu.
  4. Select an endpoint from the list. Click Next.
  5. Select the endpoint attributes you want to include in the data structure. Click Finish.
If you expand your new custom type in the Types tab, you can see it is a custom object type with an array items containing the fields in the endpoint that you selected.