Table Transformer - Transforming entire table
Asked by Federico Botero:

I have been fighting with this for days without a satisfying result.  

I am loading data from Jira and need to transform it with Table Transformer to fit my needs.

**Example and columns:**

Key \| ABC-657 (if S=Parent) or AAA-657 AAA-658 (If S=Child)

S \| Parent or Child

Parent Key \| ABC-657

Sponsor \| Super Sponsor (SSAB)

Labels \| #AA-Type or AA-Type or AA-TYPE

Description \| Long Text Long Text Long Text Long Text Long Text Magic Sentence 1 Long Text Long Text Long Text Long Text Long Text Long Text Long Text Long Text Magic Sentence 2 Long Text Long Text Long Text Long Text Long Text Long Text

<br />

STEP 1 **(Works fine)**: SELECT TOP 2 'Key', // just for testing purposes

STEP 2 **(Works fine)**: CASE WHEN 'Labels' LIKE "%AA-Type%" THEN "AA-Type" ELSE NULL END AS AA-Type,

*** ** * ** ***

STEP 3: For 'Description' column, flatten the text VARCHAR  
Then RETURN the String Between string "%Magic Sentence 1%" and string "%Magic Sentence 2%". ELSE IF String not Found THEN "Formating error" AS 'Short Description'

STEP 4: Hide 'Description' and 'Short_Description' column // to improve performance for testing.

STEP 5: COUNT CHAR 'Short_Description' AS 'SD_Count'. IF 'SD_Count' NULL OR \<155 THEN "Description needs fixing" AS 'Error' ELSE "Description OK"

*** ** * ** ***

<br />

STEP 6 **(Works fine)** : IF 'Sponsor' NOT NULL THEN  
WHEN 'Sponsor' LIKE "%SSAB%" THEN "SSAB"  
WHEN 'Sponsor' LIKE "%SSEF%" THEN "DEF"  
IF 'Parent Key' not NULL then  
WHEN 'Parent Key' LIKE "%SSAB%" THEN "SSAB"  
WHEN 'Parent Key' LIKE "%SSEF%" THEN "SSEF"

*** ** * ** ***

<br />

**This code applies for 2 Tables which are then joined and a new Table transformer comes in:**   
Same Columns.  

STEP 1: If 'Sponsor' NULL AND 'S'="Child", THEN MATCH value of 'Parent Key' with All values in column 'Schl?ssel'. IF MATCH THEN RETURN Value for 'Sponsor' of matching row. ELSE IF 'S'="Parent" THEN Return value for 'Sponsor'. ELSE if no match THEN "Error - no Sponsor" AS 'Sponsor Short'  

Step 2: IF 'S'="Parent" MATCH the value in 'Key' with all values in column 'Parent Key'.  
IF No match, THEN "No Children" ELSE RETURN COUNT of MATCHES AS 'Children'


Answers:
author: Stiltsoft support
body: Hi [@Federico Botero](/t5/user/viewprofilepage/user-id/5366178) ,

Better refer to our [support](https://stiltsoft.atlassian.net/servicedesk/customer/portal/14). Attach the page storage format of your page (upper right corner -\> menu ... -\> View storage format), so we'll be able to recreate your macros and their SQL queries. And attach the screenshots of your Jira Issues macros (in a published state with visible headers and 4-5 rows of data) - these tables won't be recreated via the page storage.

In general, you may use the SPLIT function to split your string by your "magic sentence" markers (if they are stable across the column). For example, you may check the last reply of [this Community thread](https://community.atlassian.com/t5/Confluence-questions/Why-is-my-Gantt-chart-not-showing-the-JIRA-ticket-names/qaq-p/1359981).

To hide specific columns, you just need not to list them. I mean use not "SELECT \* FROM ...", but "SELECT 'Column 1', 'Column 2' FROM ..." - here you list all the columns that need to be seen. But, as later you refer to them, you need to do it in the last (external) Table Transformer macro.

To count the length of your descriptions, you may use the [LENGTH](https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_length2) function. The previous link leads to a SQL simulator and [here](https://community.atlassian.com/t5/Confluence-questions/How-to-get-a-vote-count-from-the-data-in-a-table-cell/qaq-p/2001044) you may see an example of this function inside the Table Transformer macro. The statuses are set with the help of the CASE WHEN statement that seems to work fine for you on the Step 2.

Hope I was able to give you (and other users who will come across this question) some useful hints.

What concerns the last two steps when the second table is added, here I got confused without the real visual data. :) So, let's move to the support where you will be able to share your real screenshots - seems that it should not be that complex.


Tags: confluence-server

filter

server

sql

table