Modify Footers - Display SPSS Custom Attribute

From Q
Jump to navigation Jump to search

This Rule shows the comment from the question selected in the blue drop-down in the footer of the table. Q will automatically create variable comments when your SPSS data file contains custom attributes. SPSS custom attributes may contain information about the original survey design (such as the original question text), making it useful to include this information in the footer of tables. You may manually edit these comments in the Variables and Questions Context Menu.

This Rule allows you to optionally enter prefix text that will be removed from the start of all comments. For example, if your comment was "Question text: Choose your gender", then you would enter "Question text: " (including the space) as your prefix, resulting in a final table footer of "Choose your gender".

Technical details

This Rule requires Q 4.11 or later.

How to apply this rule

For the first time in a project

  • Select the table(s)/chart(s) that you wish to apply the rule to.
  • Start typing the name of the Rule into the Search features and data box in the top right of the Q window.
  • Click on the Rule when it appears in the QScripts and Rules section of the search results.


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

Additional applications of the rule

  • Select a table or chart that has the rule and any table(s)/chart(s) that you wish to apply the rule to.
  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to apply.
  • Click on the Apply drop-down and choose your desired option.
  • Check New items to have it automatically applied to new items that you create. Use Edit > Project Options > Save as Template to create a new project template that automatically uses this rule.

Removing the rule

  • Select the table(s)/chart(s) that you wish to remove the rule from.
  • Press the Rules tab (bottom-right corner).
  • Press Apply next to the rule you wish to remove and choose the appropriate option.

How to modify the rule

  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to modify.
  • Click Edit Rule and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).


includeWeb('QScript Utility Functions');
includeWeb('Table JavaScript Utility Functions'); 


if (fileFormatVersion() < 8.77) {
    alert('This Rule requires a newer version of Q (i.e., 4.11 or newer).');
} else {
    // Create form
    form.setHeading('Display SPSS Custom Attribute');
    form.setSummary(correctTerminology('Display SPSS custom attribute for questions in the footer'));
    const description_text = 'This rule shows the comment from imported SPSS data for any question selected in the ' +
                              (inDisplayr() ? 'Rows' : 'blue drop-down') +
                              ' in the footer of the table';
    let description = form.newLabel(correctTerminology(description_text));
    description.lineBreakAfter = true;
    let prefix_text = form.newLabel('You can also choose to remove text from the beginning of the comment');
    prefix_text.lineBreakAfter = true;
    let lbl_prefix = form.newLabel('Comment prefix (will be removed):');
    let txt_prefix = form.newTextBox('txtPrefix');
    form.setInputControls([description, prefix_text, lbl_prefix, txt_prefix]);

    let comment = table.blueQuestion.variables[0].comment;
    if (comment) {
        let prefix = txt_prefix.getValue();
        if (prefix && comment.length >= prefix.length && comment.substring(0, prefix.length) == prefix)
            comment = comment.substring(prefix.length);

        let footers = table.extraFooters;
        table.extraFooters = footers;

See also