Warning for Missing Variables

From Q
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