There may be times you want to attach a piece of information (a value) to your application as a whole. For example, imagine that your application tracks a project. The project has one start date which affects multiple tasks within your project. You want to reference this one start date in formulas without entering it for each task. No problem. Just create an application variable to contain the date. Then you can refer to this variable in multiple places throughout your project. The best part is, if the start date changes for some reason, you only need to edit it in one place, and Quickbase updates the value throughout your application. You can create as many application variables as you want.
You can use application variables in two contexts:
-
As a value in Quickbase formulas.
-
When you're using XML to make API calls. Application variables are output in API_GetSchema and API_DoQuery (APIDoQuery&fmt=structured) results, and with structured XML from table reports.
Note: When you clone an application, its variables are cloned as well.
To create an application variable:
-
From the app home page, click Settings.
-
Click Variables.
-
Click the New Variable button.
A dialog to enter the variable's name and value appears.
-
Give the variable a name.
This is the name you'll use to refer to the variable elsewhere (within formulas, for example).
-
Enter the number, date, or text that is the variable's value.
Note that the variable's value is always treated as Text within a formula, unless you convert it to another data type using formula functions (such as ToDate()).
-
Click OK.
The new variable appears in the Variables list. Click the variable name in the list to edit a variable value.
To delete an application variable:
-
From the app home page, click Settings.
-
Click Variables.
-
Complete one of the following tasks:
-
To delete one variable, select the checkbox to the left of the variable, then click the delete icon () in the rightmost column of the table.
-
To delete more than one variable, select the checkbox to the left of each variable, then click Delete above the table.
-
-
Click Delete to confirm the deletion.
To refer to a variable from within a formula:
If you want to refer to a variable within a formula, you refer to it same way you reference a value in a field; you enclose the variable name in brackets, like this: [Project Start Date]
However, a simple variable reference may not be enough to get the results you want. Variables are always text. If you want the variable to act like another data type, you need to let Quickbase know. For example, even if you type a date in as a variable, you must convert it from text into a date using the ToDate() function. The formula ToDate([Project Start Date]) produces the desired result. You could insert that function within a larger formula to use the application variable to calculate durations or get other results.
For example, you can create an application variable named "Project Start Date", and whose value is "01-01-2013". You then can use a Formula Date field that computes how old, versus the project start date, an issue is when it was closed, by using the following formula:
ToDays([Date Closed]-ToDate([Project Start Date]))
This is equivalent to:
ToDays([Date Closed]-ToDate("01-01-2013"))
The application variable becomes useful if you have many formulas that depend on this one start date. Correcting the start date is much easier if it's captured in one place as an application variable compared to finding the text embedded in multiple formulas.