Introduction
Q names the tables and charts in the report with the contents of the Blue and Brown drop-down menus for each table. Sometimes you may need to override these names with your own names, or those specified by a client. While names can be entered manually by right-clicking an item in the report and selecting Rename, you can also rename the items in your report programmatically. This article describes how to automatically rename the table names in your Q report using a QScript.
Method
1. Select your table.
2. Go to Automate > Open QScript (Macro) Editor.
3. Paste the below into the editor:
includeWeb("QScript Selection Functions");
// Specify your list of table names here
var table_names = ["Table 1",
"Table 2",
"Table 3"];
// Renaming items in the "Report"
var target_group = project.report;
// Get all of the tables, plots, and other items in the report.
var items = [];
recursiveGetAllItemsInGroup(target_group, items);
// Rename tables/plots/etc in order of their appearance in the report.
if (table_names.length > items.length)
log("There are more names specified in this script (" + table_names.length + ") than there are items in the report (" + items.length +"). Modify the list of names and run the script again.");
else {
table_names.forEach(function (name, ind) {
items[ind].name = name;
});
}
if (items.length > table_names.length)
log("There are more items in the report (" + items.length + ") than there are names specified in this script (" + table_names.length +"). Some items have not been renamed.");
In this code:
- You can change the table names, as required, by simply updating the list at the top called
table_names
. The order of the list must match the order of the tables in your project. - The code uses the
recursiveGetAllItemsInGroup
function to return all items in the report. - It then loops through every report item using
forEach
and updates thename
using the current item in thetable_names
list. - Note, there are built-in validations if the number of specified tables does not match the number of tables in your report.
- If you make changes to the tables and need to rename them again, the script can be re-run.
4. Press the Play button.
Next
How to Add the Base Size to the Table Name
See Also
How to Create a Custom QScript