Warning for Missing Variables
Jump to navigation
Jump to search
This snippet demonstrates the use of the function getVariableByName() to check whether or not a data file contains a particular variable. If the variable named does not exist, then the function returns the value null.
// This pops up a message if the data file does not contain a variable with the name 'weight'.
// You could expand this out to make a script that checks whether new data files have been outfiled correctly by your supplier.
if (project.dataFiles[0].getVariableByName("weight") == null)
alert("Data file does not contain a variable called 'weight'.");
See also
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.