Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
kavita25
Partner - Specialist
Partner - Specialist

For loop id should be as null or zero

Hello Everyone,

Load * Inline [

Id

1

2

3

4

];

 

M passing these ids in another table through for loop, but if these ids does not exist in another table it throws an error, id does not exist.

 

I want to continue the for loop and if the id does not exist it should save as null or zero.

 

Please help me with this logic.

@Anil_Babu_Samineni

 

Thanks,

Kavita

Labels (1)
7 Replies
PrashantSangle

if you want continue reload with error then try below logic

before loop start ------------>>

set errormode=0; 

------------------------->>>>

after loop end then again

set errormode = 1;

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Vegar
MVP
MVP

You could do a check before performing your load if the data expect to exist exsists, and I'd not then skip your load statement.

<your loop on vValue>

IF <logical test> THEN

<your load statement using vValue>

ELSE

Trace WARNING: $(vValue) was skipped in loop;

ENDIF

<trigger next vValue in your loop>

Anil_Babu_Samineni

@kavita25 I suggest the same way what @PrashantSangle shared, But I would recommend inside the loop rather before and after to avoid the genuine errors.

But, I am curious why you are comparing with ID that is not available in second table?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
kavita25
Partner - Specialist
Partner - Specialist
Author

Hello @Anil_Babu_Samineni I tried that but I am also storing the data in qvd. But in the qvd the data is stored only the data before the error.

I am doing this to get Worklog data from JIRA connector.

Also, I am doing this, because I want Ids from Issues table and get those ids only from the Worklog table.

Please suggest me.

Thanks,

Kavita

 

kavita25
Partner - Specialist
Partner - Specialist
Author

@PrashantSangle I tried the code. Yes its skipping those errors. But its not saving the whole data except for those issues which does not exist. It saves only the data before error occurs.

 

Thank You for the suggestion.

 

 

PrashantSangle

Hi,

try with below logic.

Test1:
Load * Inline [
Region
A
B
];
 
NoConcatenate
Test2:
Load * Inline [
Region
B
C
];
 
NoConcatenate
Test3:
Load * Inline [
Region
C
D
];
 
NoConcatenate
Final:
Load * Inline [
Region
];
 
Set errormode=0;
 
for each a in 1,7,2,4,3,5
Concatenate(Final)
    LOAD * Resident Test$(a);
next;
 
Set errormode=1;
 
Drop table Test1,Test2,Test3;
Exit Script;
 
Regards,
Prashant Sangle
Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
raju_insights
Partner - Creator III
Partner - Creator III

@kavita25 are you expecting something like this?

 

InlineTable:
LOAD * Inline [
Id
1
2
3
4
];

OtherTable:
LOAD * Inline [
Id, DIM
1, A
2, B
4, C
];

// Create a mapping table for IDs present in OtherTable
Map_IdExists:
MAPPING LOAD
Id,
Id as Exists
RESIDENT OtherTable;

// Initialize a temporary table to store results
NoConcatenate
TempResultTable:
LOAD * INLINE [
Id, DIM
];

FOR i = 0 TO NoOfRows('InlineTable') - 1
LET vId = Peek('Id', i, 'InlineTable');
LET vExists = ApplyMap('Map_IdExists', vId, 'NotFound');

IF vExists = 'NotFound' THEN
// If ID does not exist in OtherTable, add it with NULL or 0 for DIM
CONCATENATE (TempResultTable)
LOAD
NULL() AS Id, // Replace NULL() with 0 if you prefer 0 over NULL
NULL() AS DIM // Replace NULL() with 0 if you prefer 0 over NULL
AUTOGENERATE 1
;
ELSE
// If ID exists, fetch and add its corresponding row from OtherTable
CONCATENATE (TempResultTable)
LOAD
Id,
DIM
RESIDENT OtherTable
WHERE Id = $(vId)
;
ENDIF
NEXT

// Load the final results into ResultTable
NoConcatenate
ResultTable:
LOAD DISTINCT
Id,
DIM
RESIDENT TempResultTable;

// Cleanup
DROP TABLES TempResultTable, InlineTable, OtherTable;