Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
43918084
Creator II

combine tables with for loop

I have been struggling with trying to combine 3 tables while running a for loop.  

The reason of the for loop is that the data of 2 tables can only be retrieved line by line.

My apology that I m new to scripting and if any expert can give me guidance and suggest reading for my learning, I would be very grateful.

TABLE CONTENT

=======================================================

Table test0  (this is the master tabe to update another 2 tables' value to)

test0:
Load * Inline
[
key, Estimate, timespent, logged
GTT-2200,,,
GTT-2099,,,
];

 

2nd Table  : Worklog.  (This is a table where the key value can only be extracted line by line)

key Logged
GTT-2099  
GTT-2200  2d
GTT-2200  4h

 

3rd  Table  : History  (This is a table where the key value can only be extracted line by line)

key field from  to
GTT-2099      
GTT-2200  timeoriginalestimate 144000 115200
GTT-2200  timeestimate 44000 5200

 

I have tried below script but the table return blank.

 

LIB CONNECT TO 'JIRA_PROD';
 
 
 
 
test0:
Load * Inline
[
key, Estimate, timespent, logged
GTT-2200,,,
GTT-2099,,,
 
 
];
 
let i=0;
For i = 0 to 1
 
let vkey= peek('key', i, 'test0');
 
 
left join(test0)
 
//test1:
LOAD
    '$(i)' as row,
    '$(vkey)' as [key],
timeSpent as [logged], 
timeSpentSeconds as [timeSpentSeconds];
 
 
SELECT 
timeSpent,
timeSpentSeconds
 
FROM Worklog
WITH PROPERTIES (
issueIdOrKey='$(vkey)'
);
 
left join(test0)
LOAD
'$(i)' as row,
'$(vkey)' as [key],
field as [field],
    from as [from], 
fromString as [fromString], 
to as [to], 
toString as [toString]
    
   
 where WildMatch(field, '*timeoriginalestimate*') or WildMatch(field, '*timeestimate*');
 
SELECT 
field,
    from,
fromString,
to,
toString
 
FROM History
 
WITH PROPERTIES (
issueIdOrKey='$(vkey)');
 
next

 

Labels (3)
2 Replies
madelonjansen
Partner Ambassador

I think the biggest problem is that you are trying to join to the original table from within the For loop.
It will join mulitple tables with the same columns, but different values.

I'd suggest you let those tables 'auto concatenate' and join the whole thing at the end.

 

marcus_sommer

I don't understand why you want to run the tables record for record but join-approaches within a loop are usually not possible respectively only within very specific scenarios - especially because the first added fields becomes key-fields within the next iteration.