Move Data - Move Variables to New Position

From Q
Jump to navigation Jump to search

Move a selection of variables to a different position in the Variables and Questions tab. This may save time compared to dragging and dropping or using the arrow buttons in the top toolbar when you have a lot of variables to move, or you have a very long list of variables.

When you use this option you will be asked to select all the variables that you want to move, and then you will be asked to select the variable that you want to move them below. The variables will be moved to the selected position, and their current ordering will be preserved.

How to apply this QScript

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Click on the QScript when it appears in the QScripts and Rules section of the search results.

OR

  • Select Automate > Browse Online Library.
  • Select this QScript from the list.

Customizing the QScript

This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.

Customizing QScripts in Q4.11 and more recent versions

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
  • Press Edit a Copy (bottom-left corner of the preview).
  • Modify the JavaScript (see QScripts for more detail on this).
  • Either:
    • Run the QScript, by pressing the blue triangle button.
    • Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.

Customizing QScripts in older versions

  • Copy the JavaScript shown on this page.
  • Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
  • Modify the JavaScript (see QScripts for more detail on this).
  • Run the file using Automate > Run QScript (Macro) from File.

JavaScript

includeWeb("QScript Selection Functions");

if (!main())
    log("QScript cancelled.");

function main() {
    var data_file = requestOneDataFileFromProject(true);
    if (data_file == null) {
        return false
    }; 
    var variables_to_move = selectManyVariablesByNameAndLabel("Select the variables that you want to move.", data_file.variables, true).variables;
    var variable_to_move_after = selectOneVariableByNameAndLabel("Select the variable you want to move the variables after.", data_file.variables, false);
    data_file.moveAfter(variables_to_move, variable_to_move_after);
    return true;
}

See also