Use Case

You have two tables:

  • T1 with issues (issue keys plus some additional data)
  • T2 with defects (defect keys plus some additional data)

The T1 table is always present. But the T2 table may be or may not be present at all (no defects - no table). It can happen, for example, if you use the Jira Issues macro to generate tables.

If the T2 table exists, then each defect is linked to the specific issue from the T1 table (see the T2.'Linked Issue' column on the first screenshot).

You need to get the "issue-defect" list with all the additional fields from both tables if there are any defects. If everything is okay, you need to avoid SQL query errors and print the "No Defects" text.

Solution

  1. Switch the page to the edit mode.
  2. Insert the Table Transformer macro and paste the tables or the macros outputting tables within the macro body.
  3. Select the macro and click Edit.
  4. In the Presets tab select Custom transformation and click Next.
  5. Enter the following SQL query:

    IF OBJECT_ID("T2") IS NOT NULL
    SELECT * FROM T1 JOIN T2 ON T1.'Key'=T2.'Linked Issue'
    ELSE
    SELECT FIRST("No Defects") AS 'Defects' FROM T1
    SQL
  6. Go to the Options tab.
  7. Enable the Show result as plain text option.
  8. Save the macro and the page.

The behavior when both the T1 and T2 tables are present:

The behavior when only the T1 table is present: