Creating JavaScript Variables

From Q
Jump to navigation Jump to search

This page describes how to create new variables programmatically. See JavaScript Variables for an introduction and explanation of how to create them via the menus.

// Working on Phone.sav, this creates a new JavaScript variable called weight.
project.dataFiles[0].newJavaScriptVariable("q1 == 1 ? 0.5 : 1.5", false, "weight", "Weight", null);

// Working on Phone.sav, the following creates a new JavaScript Variable called weight, positioned below Q1.
var _qBelow = project.dataFiles[0].getVariableByName("q1");
project.dataFiles[0].newJavaScriptVariable("q1 == 1 ? 0.5 : 1.5", false, "weight", "Weight", _qBelow);

See also