Hide/Unhide - Hide Questions with Many Categories
This QScript will go through your project and hide questions that have a large number of categories. You may specify the number of categories that you wish to consider large. This can be helpful when you wish to automatically create a large number of tables, using Smart Tables, Basic Tables or Tables - Banner Tables, for example, and some of the resulting tables would be too large and hence unhelpful. Rather than sorting through your list of questions to determine which to keep, you can use this QScript to first hide any questions that would generate large tables.
The hidden questions can be automatically unhidden later by using Hide/Unhide - Unhide Questions with Many Categories.
Technical Details
Questions which are Pick One - Multi or Pick Any - Grid are considered large when the number of rows or columns in their SUMMARY tables exceeds the maximum specified value.
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
JavaScript
// Hide questions with a large number of categories
includeWeb("QScript Selection Functions");
includeWeb("QScript Data Reduction Functions");
includeWeb("QScript Functions to Generate Outputs");
if (!main())
log("QScript Cancelled.");
else
conditionallyEmptyLog("A description of the hidden questions has been added to your report.")
function main() {
var data_files = dataFileSelection();
var report_message = "The following questions have been hidden. To unhide them, select Automate > Browse Online Library > Hide/Unhide > Unhide Large Questions.";
var hidden_tag = "Hidden - Large number of Categories";
var max_categories = 20;
max_categories = prompt("Specify the maximum number of categories to keep:", max_categories);
var hidden_questions = [];
var candidate_questions = getAllQuestionsByTypes(data_files, ["Pick One", "Pick One - Multi", "Pick Any", "Pick Any - Grid", "Pick Any - Compact"]);
candidate_questions = candidate_questions.filter(function (q) { return !q.isHidden; });
candidate_questions.forEach(function (q) {
if (largestDimension(q) > max_categories) {
q.isHidden = true;
hidden_questions.push(q.name);
q.name = q.name + " " + hidden_tag;
}
});
if (hidden_questions.length > 0) {
var new_group = project.report.appendGroup();
new_group.name = "Hidden Questions";
var report = simpleHTMLReport([report_message].concat(hidden_questions), "Hidden Questions", new_group, true, false);
return true;
} else {
log("No large questions to hide.");
return false;
}
}
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- 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.